UNABLE TO PERFORM THE ASSIGNMENT
Mostrar comentarios más antiguos
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 comentarios
yogeshwari patel
el 3 de Abr. de 2023
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
el 3 de Abr. de 2023
Dyuman Joshi
el 3 de Abr. de 2023
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
el 3 de Abr. de 2023
Respuesta aceptada
Más respuestas (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.
1 comentario
yogeshwari patel
el 3 de Abr. de 2023
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!