Error in plotting - indices not compatible

조회 수: 11 (최근 30일)
Sabrina Garland
Sabrina Garland 2023년 9월 18일
댓글: Matt J 2023년 9월 19일
I have the following code -
syms y t g
f1 = -2*g*(t.^3 +t.^2)/((1 - y).^(1-2*g)) + 2*g*(3-t)*(3 - t.^2)^2./(((2 - t).^2).*y.^(1-2*g)) + (8*g*(t+1))./(y.^(1- 2*g)) - 2*g*(3-t)*(3 - 2*t).^2./(((2 - t).^2).*(1 - y).^(1-2*g));
[N1,D1] = numden(f1);
f2 = t - (((y.^(2*g))*(2/3) - (((1-y).^(2*g)).*((3 - 2*t)./(3*(2-t)))))./((y.^(2*g)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(2*g)).*(t/3)));
[N2,D2] = numden(f2);
tsol = solve(N2==0,t,'MaxDegree',3);
N1_subs_tsol1 = subs(N1,t,tsol(1));
N1_subs_tsol2 = subs(N1,t,tsol(2));
N1_subs_tsol3 = subs(N1,t,tsol(3));
G = 0.01:0.001:0.12;
soly1(1) = vpasolve(subs(N1_subs_tsol1/(y*(1-y)^(2*g)),g,G(1))==0,y);
soly2(1) = vpasolve(subs(N1_subs_tsol2/y/(-2*g),g,G(1))==0,y);
soly3(1) = vpasolve(subs(N1_subs_tsol3/y/(-2*g),g,G(1))==0,y);
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in sym/privsubsasgn (line 1200)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);

Error in indexing (line 1031)
C = privsubsasgn(L,R,inds{:});
for i = 2:numel(G)
soly1(i) = vpasolve(subs(N1_subs_tsol1/(y*(1-y)^(2*g)),g,G(i))==0,y,soly1(i-1));
soly2(i) = vpasolve(subs(N1_subs_tsol2/y/(-2*g),g,G(i))==0,y,soly2(i-1));
soly3(i) = vpasolve(subs(N1_subs_tsol3/y/(-2*g),g,G(i))==0,y,soly3(i-1));
end
solt1 = arrayfun(@(soly1,G)subs(tsol(1),[y,g],[soly1,G]),soly1,G);
solt2 = arrayfun(@(soly2,G)subs(tsol(2),[y,g],[soly2,G]),soly2,G);
solt3 = arrayfun(@(soly3,G)subs(tsol(3),[y,g],[soly3,G]),soly3,G);
hold on
p1 = plot(G,soly1,'r');
%plot(G,solt1,'r')
p2 = plot(G,soly2,'b');
%plot(G,solt2,'b')
p3 = plot(G,1./(1+(1/3).^(1./(1-2*G))),'g');
legend([p1,p2,p3],[" Slice 1","Slice 2","Slice 3"])
xlabel("g")
hold off
grid on
Why I am getting the following error -
Unable to perform assignment because the
indices on the left side are not compatible
with the size of the right side.
Error in sym/privsubsasgn (line 1200)
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in indexing (line 1031)
C = privsubsasgn(L,R,inds{:});
Please help @Torsten

답변 (1개)

Matt J
Matt J 2023년 9월 18일
편집: Matt J 2023년 9월 18일
vpasolve is returning empty (because it found no solution), so you cannot assign it to soly3(1)
>> vpasolve(subs(N1_subs_tsol3/y/(-2*g),g,G(1))==0,y)
ans =
Empty sym: 0-by-1
  댓글 수: 5
Sabrina Garland
Sabrina Garland 2023년 9월 19일
How to do that?
Help @Torsten
Matt J
Matt J 2023년 9월 19일
That's what my last comment shows.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by