Assignment between unlike types is not allowed. for loop
13 次查看(过去 30 天)
显示 更早的评论
Hello! I'm trying to solve a system of nonlinear equations,but my license doesn't support the fsolve function. The s1 is a parameter that takes values between 0 and 500, so i wanted to put that in a for loop and save the 3 values that i want(x=x1,s2=x2,D=x3) in arrays, in order to plot them.
m1=0.2;
m2=m1;
k1=15;
k2=25;
y1=0.4;
y2=0.3;
a1=0.05;
a2=5;
s1f=500;
s2f=600;
syms x1 x2 x3
eqns=[x3-(m1*s1)/(k1+s1+a2*x2)-(m2*x2)./(k2+x2+a1*s1)==0,x1-y1*(s1f-s1)+y2*(s2f-x2)==0,x3.*(s2f-x2)-((m2*x2)./(y2*(k2+x2+a1*s1))).*(y1*(s1f-s1)+y2*(s2f-x2))==0];
for s1=0:1:500
vars=[x1 x2 x3];
[sol1,sol2,sol3]=vpasolve(eqns,vars)
x(s1+1)=sol1;
s2(s1+1)=sol2;
D(s1+1)=sol3;
end
plot(x,D)
When i run the m.file i get:
roots2d
sol1 =
20.0
sol2 =
0
sol3 =
0
Assignment between unlike types is not allowed.
Error in roots2d (line 19)
x(s1+1)=sol1;
What am I missing here? Thank you in advance!
0 个评论
采纳的回答
Walter Roberson
2018-11-6
You do not initialize x in this code. It probably has a value left over in the workspace.
It is recommended that you test whether you got a non-empty solution before you try to assign it into the array.
Your code uses s1 before defining it, and then tries to give it a changing value by using a "for" loop. You need to
syms s1
before defining the equations, and inside the loop you need
[sol1, sol2, sol3] = vpasolve( subs(eqns), vars);
3 个评论
Walter Roberson
2018-11-7
The case of s1 = 0 is degenerate and has only one solution. Otherwise the equations involve a quadratic with two solutions for each s1 value (at s1 = 0, the two are the same value.)
更多回答(1 个)
BHOLANATH KUMBHAKAR
2019-9-9
syms x al lm mu;
lm=3;
mu=5;
n=round(10/.01);
al=0:0.01:10;
for i=1:n+1
f(i)=((mu-lm*x)^((lm/al(i))-1))/(1-x)
end
z(i)=int(f,0,.99999)
--------------------------------------------------------------------------------
Assignment between unlike types is not allowed.
Error in Untitled3 (line 7)
f(i)=((mu-lm*x)^((lm/al(i))-1))/(1-x)
why is it say????can anyone help me???
1 个评论
Walter Roberson
2019-9-9
I suspect that you have an existing variable named f that is interfering.
z(i)=int(f,0,.99999)
Caution, that is after the for loop and tries to integrate all of entries in the vector f with respect to the default variable, and assign the result to the single location z(i)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!