# طلب المساعدة في الكود

(system) #1

[QUOTE][/QUOTE]

السلام عليكم
أرجو مساعدتي في عمل المشروع

(Ahmed) #2

وعليكم السلام
لا يوجد اي مشروع في الصورة التي قدمتها

(system) #3

بعتذر لم انتبه
الحين موجود المطلوب

وشكرا

(Ahmed) #4

[CENTER]هذا هو الحل

والكود كالتالي

``````
clear all;
close all;
clc;

%   Requesting the number of meshes----------------------------------------
MNIsCorrect=0;
while MNIsCorrect==0
%       Checking The User Input if is not Empty, is Scalar, is >=2 and it
%       is an Integer
MNumber = input('Enter the number of meshes:
');
if isempty(MNumber)|| ~isscalar(MNumber) || MNumber<2||floor(MNumber)~=MNumber
disp('Meshes Number Cannot be Empty, Should be a Scalar,Should be >=2 and Should be an Integer . Try again.');
continue;
end
%       If it is a Correct Input (We Stop the While Loop)
MNIsCorrect=1;
end
%   Requesting the Resistances Vector (2*MNumber-1)Values------------------
RNumber=2*MNumber-1;
RNIsCorrect=0;
while RNIsCorrect==0
ResistorVector = input(['Enter ',num2str(RNumber),' resistors in ohm in the form of [R1 R2 ... R',num2str(RNumber),']:
']);
[m n]=size(ResistorVector); % ResistorVector Dimensions
%       Checking The User Input
%       If The Resistance Number and ResistorVector format are correct
if RNumber~=n ||m~=1
disp(['Total Number of resistances should be ',num2str(RNumber),'. Try again.']);
continue;
end
%       If The Resistances Are All Positive
if any(ResistorVector < 0)
disp('The Resistances Should Not be Negative. Try again.');
continue;
end
%       If All The Resistances Are zeros
if all(ResistorVector==0)
disp('The Resistances Should Not be All zeros. Try again.');
continue;
end
%       If it is a Correct Input (We Stop the While Loop)
RNIsCorrect=1;
end
%   Requesting the Voltage Values------------------------------------------
VVIsCorrect=0;
while VVIsCorrect==0
VVector= input('Enter voltage values in volt, [V1 V2]:
');
[x y]=size(VVector);% VoltageVector Dimensions
%       Checking User Input------------------------------------------------
%       If The Voltages Number and Voltage Vector format are correct
if y~=2 ||x~=1
disp('Voltage Values Should be in the form of [V1 V2]. Try again.');
end
%       If it is a Correct Input (We Stop the While Loop
VVIsCorrect=1;
end
%   Building The System of Equations R.I=V
%   I=inv(R)*V
%   R=Rd+Rb
%   Creating the Diagonal Matrix Rd
Rd=diag(ResistorVector(1:2:end));
%   Creating block matrics Rb1,Rb2,...,Rbn-1
BlockResistance=ResistorVector(2:2:end);
Rb=zeros(MNumber);
for i=1:length(BlockResistance)
Rb=Rb+blkdiag(zeros(i-1),[1 -1;-1 1]*BlockResistance(i),zeros(length(BlockResistance)-i));
end
%   Summing the 2 Matrics Rd and Rb
R=Rd+Rb;
%   Solving the System
V=[VVector(1);zeros(MNumber-2,1);-VVector(2)];
I=inv(R)*V;
%   Outputing the solution
disp('The resistance matrix to solve the mesh current is:');
R
disp('The voltage vector to solve the mesh current is:');
V
disp('The mesh currents are:');
I

``````

[/center]