UNABLE TO PERFORM THE ASSIGNMENT
이전 댓글 표시
syms a x z Finaleq_1 K alpha A
C=zeros(1,'sym')
Finaleq_1=zeros(1,2,'sym')
A=zeros(1,'sym')
series(x)=sym(zeros(1,1));
C(1)=a;
C(2)=0;
for i=1:2
T1=0;
T2=0;
T3=0;
T4=0;
C(i+2)=z;
for r=1:i
T2=T2+kroneckerDelta(sym(r-2))*(i-r+1)*(i-r+2)*C(i-r+3);
T3=T3+C(r)*(i-r+1)*C(i-r+2);
T4=T4+kroneckerDelta(sym(r-2))*C(i-r+1);
for m=1:r
%
T1=T1+kroneckerDelta(sym(m-2))*C(r-m+1)*(i-r+1)*(i-r+2)*C(i-r+3)
end
% fprintf('*******')
end
% fprintf('%%%%%%')
Finaleq_1=T1+T2+2*T3+2*K*i*C(i+1)-alpha*T4;
A=solve(Finaleq_1,z) % tHE PROBLEM IS HERE .
C(i+2)=A
end
Solving the equation will give a sclar quantity but it will be in variable form and A is also a scalar .Then why it is showing an error the following error:
Unable to perform assignment because the left and right sides have a different number of elements.
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
C = privsubsasgn(L,R,inds{:});
댓글 수: 5
yogeshwari patel
2023년 4월 3일
In the second iteration of the first loop, the expression of solve() returns an empty sym array. And assigning the empty sym array is giving you the error.
Maybe check all the formulae used.
syms a x z K alpha
Finaleq_1=zeros(1,2,'sym');
A=zeros(1,1,'sym');
series(x)=zeros(1,1,'sym');
C=[a 0];
for i=1:2
T1=0;
T2=0;
T3=0;
T4=0;
C(i+2)=z;
for r=1:i
T2=T2+kroneckerDelta(sym(r-2))*(i-r+1)*(i-r+2)*C(i-r+3);
T3=T3+C(r)*(i-r+1)*C(i-r+2);
T4=T4+kroneckerDelta(sym(r-2))*C(i-r+1);
for m=1:r
%
T1=T1+kroneckerDelta(sym(m-2))*C(r-m+1)*(i-r+1)*(i-r+2)*C(i-r+3);
end
% fprintf('*******')
end
% fprintf('%%%%%%')
Finaleq_1=T1+T2+2*T3+2*K*i*C(i+1)-alpha*T4
A=solve(Finaleq_1,z) % tHE PROBLEM IS HERE .
C(i+2)=A;
end
yogeshwari patel
2023년 4월 3일
Dyuman Joshi
2023년 4월 3일
It is initially defined as a 1x1 sym array, but you are over-writing it with this command -
A=solve(Finaleq_1,z)
And you can see above as well, A is no longer 1x1 sym

yogeshwari patel
2023년 4월 3일
채택된 답변
추가 답변 (1개)
The problem is not with the solve call. The problem is on the next line. You're assuming that the equation you're solving has exactly one solution. What happens if it has multiple solutions or if it has no solutions?
syms x
solNone = solve(x == 1, x == 2, x) % no number is simultaneously equal to 1 and equal to 2
solMultiple = solve(x^2 == 4, x)
What happens if you were to try to assign either solNone (with zero elements) or solMultiple (with two elements) to one element of another vector? MATLAB throws an error.
try
solutionVector(1) = solNone; % error, too few solutions
catch ME
fprintf("This assignment failed with error '%s'\n", ME.message)
end
try
solutionVector(1) = solMultiple; % error, too many solutions
catch ME
fprintf("This assignment failed with error '%s'\n", ME.message)
end
Check the size of the vector you're trying to assign into the one element of C. You need to determine how to handle the cases where it has more or fewer elements than the part of the vector into which you're trying to store it.
카테고리
도움말 센터 및 File Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!