Solving a system of equations, with for loop ?
23 views (last 30 days)
Show older comments
Bertrand Canetti
on 21 Mar 2019
Answered: Nazer khan
on 21 Mar 2020
Hell all :)
I'm a beginner on MatLab, and I have difficulties to solve "at once" this system of equations:
TSR=7.5; %Tip Speed Ratio
%a
syms a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
x=linspace(1,TSR,10)';
eqn1=(x(1)==(4*a1-1)*sqrt((1-a1)/(1-3*a1)));
eqn2=(x(2)==(4*a2-1)*sqrt((1-a2)/(1-3*a2)));
eqn3=(x(3)==(4*a3-1)*sqrt((1-a3)/(1-3*a3)));
eqn4=(x(4)==(4*a4-1)*sqrt((1-a4)/(1-3*a4)));
eqn5=(x(5)==(4*a5-1)*sqrt((1-a5)/(1-3*a5)));
eqn6=(x(6)==(4*a6-1)*sqrt((1-a6)/(1-3*a6)));
eqn7=(x(7)==(4*a7-1)*sqrt((1-a7)/(1-3*a7)));
eqn8=(x(8)==(4*a8-1)*sqrt((1-a8)/(1-3*a8)));
eqn9=(x(9)==(4*a9-1)*sqrt((1-a9)/(1-3*a9)));
eqn10=(x(10)==(4*a10-1)*sqrt((1-a10)/(1-3*a10)));
a1=vpasolve(eqn1,a1,[1/4 1/3]); %Finding a between 1/4 and 1/3
a2=vpasolve(eqn2,a2,[1/4 1/3]);
a3=vpasolve(eqn3,a3,[1/4 1/3]);
a4=vpasolve(eqn4,a4,[1/4 1/3]);
a5=vpasolve(eqn5,a5,[1/4 1/3]);
a6=vpasolve(eqn6,a6,[1/4 1/3]);
a7=vpasolve(eqn7,a7,[1/4 1/3]);
a8=vpasolve(eqn8,a8,[1/4 1/3]);
a9=vpasolve(eqn9,a9,[1/4 1/3]);
a10=vpasolve(eqn10,a10,[1/4 1/3]);
a=[a1;a2;a3;a4;a5;a6;a7;a8;a9;a10];
Indeed, it is very repetitive and if I have 100 variables to find I cannot think about typing all the equations one by one like I did here with 10. :/
I have thought about a for loop, but I cannot manage to make it work.
Thanks in advance for you help :)
0 Comments
Accepted Answer
Alex Mcaulley
on 21 Mar 2019
This is an option:
TSR=7.5; %Tip Speed Ratio
%a
syms aux
x=linspace(1,TSR,10)';
a = zeros(size(x));
for i = 1:numel(x)
eqn = x(i)==(4*aux-1)*sqrt((1-aux)/(1-3*aux));
a(i) = double(vpasolve(eqn,aux,[1/4 1/3]));
end
More Answers (1)
Nazer khan
on 21 Mar 2020
f1(x) = −20e−0.02qD−1PD i=1 x2 i −eD−1PD i=1 cos(2πxi) + 20 + e
matlab code for this
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!