The "solve" system is not solving my variables

조회 수: 5 (최근 30일)
JingChong Ning
JingChong Ning 2023년 2월 12일
편집: Dinesh 2023년 3월 1일
I have a for loop creating a super equation that is the sum of a group of equations that could use variables A1 to A7. Each looping would increase the amount of As, which means amount of equations in that group. The super equation would then be solved.
cb = 1/5.25; %reverse of aspect ratio
cla = 2*pi; %the slope of lift vs aoa
aa = 5*pi/180; % radiant value of 5 degree
N = [3 5 7]; %list of possible N value
syms a1 a2 a3 a4 a5 a6 a7 temp
A = [a1 a2 a3 a4 a5 a6 a7]; %list of possible An
eqn = A; %list of possible equations
solved = A;
for i = 1:3
counter = N(i);
Acou = A(1:counter);
anslist = Acou;
eqncou = eqn(1:counter);
spandiv = (pi/2)/counter;
for j = 1:counter
for k = 1:counter
if rem(j,2)~=0
anslist(k) = A(k)*(sin(k*(spandiv*j)))+0.25*cb*cla*sin(k*(spandiv*j))/sin(spandiv*j);
else
anslist(k) = 0;
end
temp = temp + anslist(k);
end
eqncou(j) = temp == 0.25*cb*2*pi*aa;
end
solve(eqncou)
end
However, instead of seeing a solution in a1 to a3 or a5 or a7, a3, a5, and a7 are always missing from the solutions and instead, there is a temp in the solution. Could you tell me why?
ans =
struct with fields:
a1: [1×1 sym]
a2: [1×1 sym]
temp: [1×1 sym]
ans =
struct with fields:
a1: [1×1 sym]
a2: [1×1 sym]
a3: [1×1 sym]
a4: [1×1 sym]
temp: [1×1 sym]
ans =
struct with fields:
a1: [1×1 sym]
a2: [1×1 sym]
a3: [1×1 sym]
a4: [1×1 sym]
a5: [1×1 sym]
a6: [1×1 sym]
temp: [1×1 sym]

채택된 답변

Dinesh
Dinesh 2023년 3월 1일
편집: Dinesh 2023년 3월 1일
Hi JingChong !
I successfully reproduced this issue on my end. The problem is with how you are using the solve function. If we are not going to specify which variables to 'solve', then the 'symvar' function will determine which variable to solve for on its own. Here, in this case, it is choosing 'temp' as the variable to solve that is why we are getting temp in the solution.
Here it seems like you want to solve for the variables a1,a2 and a3 in the first iteration and a1,a2,a3,a4 and a5 in the second and so on.
So instead of simply calling 'solve(eqncou)'
replace it with
solve(eqncou , A[1:counter]);
for further details on solve function read this documentation.
Hope this helps! :)

추가 답변 (0개)

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by