In: Computer Science
Given the differential equation x′=(x+3.5)(x+1.5)3x2(x−1)x′=(x+3.5)(x+1.5)3x2(x−1).
plotting the slope field using MATLAB.
Is anybody can tell me every step with this? How to get this differential equation slope field by MATLAB? I need each step. Thanks!
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format short
f=@(t,x) (x+3.5).*(x+1.5).*3.*x.^2.*(x-1);
tval=0:0.1:4;
yval=-2:0.1:2;
[tm,ym]=meshgrid(tval,yval);
dt = tval(2) - tval(1);
dy = yval(2) - yval(1);
fv = vectorize(f);
if isa(f,'function_handle')
fv = eval(fv);
end
yp=feval(fv,tm,ym);
s = 1./max(1/dt,abs(yp)./dy)*0.35;
h = ishold;
quiver(tval,yval,s,s.*yp,0,'.r'); hold on;
quiver(tval,yval,-s,-s.*yp,0,'.r');
if h
hold on
else
hold off
end
axis([tval(1)-dt/2,tval(end)+dt/2,yval(1)-dy/2,yval(end)+dy/2])
Kindly revert for any queries
Thanks.