Error in plotting - indices not compatible

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

Respuestas (1)

Matt J
Matt J el 18 de Sept. de 2023
Editada: Matt J el 18 de Sept. de 2023

0 votos

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 comentarios

Sabrina Garland
Sabrina Garland el 18 de Sept. de 2023
What can I do to solve it?
You can rewrite the code along the following lines
tmp= vpasolve(subs(N1_subs_tsol3/y/(-2*g),g,G(1))==0,y);
if ~isempty(tmp)
soly3(1)=tmp;
else
Do something else
end
Dyuman Joshi
Dyuman Joshi el 18 de Sept. de 2023
Remove the index and store in a variable instead of storing in an element.
Sabrina Garland
Sabrina Garland el 19 de Sept. de 2023
How to do that?
Help @Torsten
Matt J
Matt J el 19 de Sept. de 2023
That's what my last comment shows.

Iniciar sesión para comentar.

Productos

Versión

R2023b

Preguntada:

el 18 de Sept. de 2023

Comentada:

el 19 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by