I'm trying to solve the following series of equations and store the positive solution for each equation
Here's the code I've used:
s=zeros(1,100);
for i=1:100
syms l0 positive
eqn(i)= .0017777*(l0^.25)/(.05-l0) == i;
s(i)=solve(eqn(i),l0);
end
But at the end I get the following error:
The following error occurred converting from sym to double: Unable to convert expression into double array.
Could anyone please help me to solve this problem?
Because of the 1/4
power in your equation, there are complex solutions.
You only want the real solutions, so specify that...
solve(eqn(i),l0,'Real',true);
This will give you the results you want.
Note that MATLAB automatically does the conversion from the symbolic output of solve
to a double, because you initialised s
to be an array of doubles, not a symbolic array. You lose precision here, but can use the answer as you would any other double array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.