UNABLE TO PERFORM THE ASSIGNMENT

2 次查看(过去 30 天)
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);
Error in indexing (line 999)
C = privsubsasgn(L,R,inds{:});
  5 个评论
Dyuman Joshi
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
yogeshwari patel 2023-4-3
Yes I agree too it after three iteration the size of matrix A change . So now how to many it as the equation is having two solutions and its is stored in 2X1 array. And I want to store the non zero value in C(i+2).

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-4-5
移动:Walter Roberson 2023-4-5
Your equation has no solutions, at least not for i = 1:2 .
Your T values come out 0 when i = 1. That leads to Finaleq_1 = 0, and then you solve() that 0 for z. MATLAB says "Oh, okay, that is solved if z = 0, then you would have 0 for the equation and 0 for z" so it returns 0 the first time, which you store into A. Then at the end of the cycle your C(i+2)=A; stores that 0 into C(3)
Then when i = 2, when r becomes 2, (i-r+3) becomes 2-2+3 = 3 so C(i-r+3) recalls that 0 (the A from the previous round.) Put that into the kroneckerDelta(sym(r-2))*(i-r+1)*(i-r+2)*C(i-r+3) and although the sym(r-2) is sym(0) and kroneckerDelta(0) is 1, with the C(i-r+3) being 0, then 0 is added to T2. Conditions for the result of the Finaleq_1 expression are slightly different this round, so you get an α coming in from a different variable, but all of the multiples of z (the variable you are solving for) are 0, so your Finaleq_1 becomes solve(constant times alpha, z) . Which has no solutions unless alpha just happens to equal 0.
So, no solution, at least not for i = 1 and i = 2.

更多回答(1 个)

Steven Lord
Steven Lord 2023-4-3
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
solNone = Empty sym: 0-by-1
solMultiple = solve(x^2 == 4, x)
solMultiple = 
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
This assignment failed with error 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.'
try
solutionVector(1) = solMultiple; % error, too many solutions
catch ME
fprintf("This assignment failed with error '%s'\n", ME.message)
end
This assignment failed with error 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.'
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 个评论
yogeshwari patel
yogeshwari patel 2023-4-3
I know that as I have serach on the MATHwork about it . But the problem is my equatain will be linear and it has only one solution. Or It will have always unique solution.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by