[Solved] System of equations with for loop (3 variables and 10 equations)

1 view (last 30 days)
Hello all :)
I am trying to solve a system of equations with for loop (3 variables and 3 equations, 10 times):
TSR=7.5; %Tip Speed Ratio
k=2;
eps_design=0.0023;
x=linspace(1,TSR,10)';
%a, a', beta_i
syms a a_prime_for beta_i_for
a = zeros(size(x));
a_prime = zeros(size(x));
beta_i = zeros(size(x));
for i = 1:numel(x)
eqn_1 = a_for/(1-a_for)==(F*cos(beta_i_for)*(1+eps_design*tan(beta_i_for)))/(8*pi*k*(sin(beta_i_for))^2);
eqn_2 = a_prime_for/(1+a_prime_for)==(F*(1-eps_design*cot(beta_i_for)))/(8*pi*k*cos(beta_i_for));
eqn_3 = tan(beta_i_for)==(1-a_for)/(x(i)*(1+a_prime_for));
eqns=[eqn_1,eqn_2,eqn_3];
S=double(vpasolve(eqns,[a_for a_prime_for beta_i_for]));
[a(i),a_prime(i),beta_i(i)]=[S.a_for,S.a_prime_for,S.beta_i_for];
end
But I get this error, and I don't understand it:
This expression cannot be assigned to multiple values. (line [a(i),a_prime(i),beta_i(i)]=[S.a_for,S.a_prime_for,S.beta_i_for];)
Error using sym.getEqnsVars>checkVariables (line 92)
Second argument must be a vector of symbolic variables.
Error in sym.getEqnsVars (line 54)
checkVariables(vars);
Error in sym/vpasolve (line 132)
[eqns,vars] = sym.getEqnsVars(varargin{1:N});
Error in Assigment1 (line 207)
S=double(vpasolve(eqns,[a_for a_prime_for beta_i_for]));
Thank you in advance for your help :)
EDIT1: changed F in eqn_1 and eqn_2 to F(i). I had not the same number of equations between the left and right sides of those equations. But I still have an error now.
Error using double
Conversion to double from struct is not possible.
Error in Assigment1 (line 207)
S=double(vpasolve(eqns,[a_for a_prime_for beta_i_for]));
EDIT2: Okay, I took away the double function and it works now. :) Here is my final code:
% -B.3 Induction factors (a, a') and beta_i
F=(Z*c_radius*C_Ldesign)./(x./TSR); %Loading Force
k=2;
%a, a', beta_i
syms a_for a_prime_for beta_i_for
a = zeros(size(x));
a_prime = zeros(size(x));
beta_i = zeros(size(x));
for i = 1:numel(x)
eqn_1 = a_for/(1-a_for)==(F(i)*cos(beta_i_for)*(1+eps_design*tan(beta_i_for)))/(8*pi*k*(sin(beta_i_for))^2);
eqn_2 = a_prime_for/(1+a_prime_for)==(F(i)*(1-eps_design*cot(beta_i_for)))/(8*pi*k*cos(beta_i_for));
eqn_3 = tan(beta_i_for)==(1-a_for)/(x(i)*(1+a_prime_for));
eqns=[eqn_1,eqn_2,eqn_3];
S=vpasolve(eqns,[a_for a_prime_for beta_i_for]);
a(i)=S.a_for;
a_prime(i)=S.a_prime_for;
beta_i(i)=S.beta_i_for;
end
By the way, F was
F =
3.3671
1.5299
0.8375
0.5207
0.3530
0.2543
0.1916
0.1494
0.1197
0.0981

Answers (0)

Community Treasure Hunt

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

Start Hunting!