The "solve" system is not solving my variables
조회 수: 5 (최근 30일)
이전 댓글 표시
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]
댓글 수: 0
채택된 답변
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]);
Hope this helps! :)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!