Using eval undefined function or variable
Show older comments
So I have a exercise to solve a differential equation and I have to use Pikar's method to draw some of the approximations.However I have trouble using eval. Here is my code:
function ex1
hold on;
grid on;
xmin=1;xmax=3;
x0=2;y0=2;
axis([xmin xmax -1,5]);
y=dsolve('Dy=x*(3*y-2)*sin(1-4*x^2)','y(2)=2','x')
t=xmin:(xmax-xmin)/100:xmax;
plot(t,eval(y),'k');
function z = ff(x,y)
z=x.*(3*y-2).*sin(1-4*(x.^2));
end
% Calculating the approximations
X=xmin:(xmax-xmin)/100:xmax;
Y=y0*ones(1,length(X));
plot(X,Y,'y');
Z=Y;
N=8;
for k=1:N
YK=y0+cumtrapz(X,ff(X,Z));
if(k==1)
plot(X,Y,'g');
elseif(k==2)
plot(X,Z,'b');
elseif(k==7)
plot(X,Z,'r');
end
Z=YK;
end
end
And the errors I am getting are :
Error using evalin
Undefined function or variable 'x'.
Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));
Error in ex1 (line 12)
plot(t,eval(y),'k');
Accepted Answer
More Answers (0)
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!