Reputation: 167
I have the following code:
syms y
x=linspace(0,1000,100);
b=solve((1/(x-y))-(1/y)=2,y)
and it does not work. I want to vectorize the solution but somehow I am missing something. I do not want to use a for to solve each value alone.
Help is greatly appreciated.
Upvotes: 2
Views: 70
Reputation: 36710
Think how you would solve it using pen and paper. You wouldn't substitute x 100 times, then solve it 100 times. Instead solve it once for y, then put in the x-values:
syms x y
%use solve once
b=solve((1/(x-y))-(1/y)==2,y)
%generate anonymous function from the solution
c=matlabFunction(b)
%evaluate anonymous function 100 times
result=c(linspace(0,1000,100))
%to get only the highest solution
max(result)
It returns a 2x100 matrix because solve
found two solutions.
Upvotes: 2