Adding Symbolic equations using while loops

4 次查看(过去 30 天)
I am attempting to create a matlab version of the KCL equation. I can't figure out a way to loop through all the possible equations and ADD them together.. as symbolic equations. I eventually need to end up with a system of equations that I can set equal to zero and then Solve. Currently this code won't even give me a single equation. It just spits out 0 unitl infinity. Any ideas on how to fix this? I dont want to have to hard code the addition of all of these possible outcomes. Thanks!!
nodes = sym('n',[1 10])
nodes(1,1)=0;
disp(nodes)
answer=inputdlg({'nodes'});
n=str2double(answer(1,1));
Resistance=Inf(n);
A=1;
B=0;
C=0;
i=0
while A < n
B = B+1;
C = C+1;
while B < n
B = B+1;
answer =inputdlg(['Enter resistance between ',num2str(A),' and ',num2str(B),' or enter "I" for infinite resistance.']);
if strcmp(answer, 'I')
i = i+1;
else
Resistance(A,B) = str2double(answer)
Resistance(B,A) = str2double(answer)
end
end
A = A+1;
B = C;
end
disp(Resistance)
Col =1;
Row =0;
C=0;
while Col < n
Row = Row+1;
C = C+1;
while Row < n
EquationExample = (nodes(1,Col)-nodes(1,Row))/(Resistance(1,Row))
disp(EquationExample)
end
Col = Col+1;
Row = C;
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by