Question
solve in matlab please

Draw the phase line for ay-ay(y2-1)(2+y), α > 0 and then using Matlab Problem 1 : graph the solution for different initial co
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Problem1 兄︸ hone plane (M うclear all close all %function to be solved a-2; yy-linspace (-2.1,1.1) figure(1) plot (yy, f (0,yy)) title(f(y) vs. y plot fxlabel ( ·x ) ylabely(x) ) grid on figure (5) (xs,ys] -ode45(f, [x ini,1],-5); plot (xs,ys, b, Linewidth,2) title( Y (ttv) vs. y plot for a-2 1.5 0.5 0.5 1.5 2.5 1.5 0.5 0.5 1.5 phase potrait plot for a 2 0 234 5 678910ytx) vs. x plot for a-2 and yo)--5 -2.5 -3.5 -4.5 -5 .1 0 03 04 05 0608 0.9 phase potrait plot for a 4 0 234 5 678910ytx) vs. x plot for a 4 and ylo)--5 -2 -2.5 .3 -3.5 -4.5 -5 .1 0 03 04 05 0608 0.9 Published with MATLAB R2018a

clear all
close all
%function to be solved
a=2;
f = @(x,y) 2.*y.*(y.^2-1).*(2+y);
yy=linspace(-2.1,1.1);
figure(1)
plot(yy,f(0,yy))
title('f(y) vs. y plot for a=2')
xlabel('y')
ylabel('f(y)')

x_ini=0;
x_end=10;
%Plotting Direction field
figure(2)
dirrfield(f,0:1:10,-3:.5:3)
hold on
%plot for different initial velocity
for v0=-10:1:10
[xs,ys] = ode45(f,[x_ini,x_end],v0); plot(xs,ys,'b','Linewidth',2)
end
hold off
title('phase potrait plot for a=2')
xlabel('x')
ylabel('y(x)')
grid on

figure(3)
[xs,ys] = ode45(f,[x_ini,1],-5); plot(xs,ys,'b','Linewidth',2)
title('y(x) vs. x plot for a=2 and y(0)=-5')
xlabel('x')
ylabel('y(x)')
grid on

%function to be solved
a=4;
f = @(x,y) 4.*y.*(y.^2-1).*(2+y);
yy=linspace(-2.1,1.1);

x_ini=0;
x_end=10;
%Plotting Direction field
figure(4)
dirrfield(f,0:1:10,-3:.5:3)
hold on
%plot for different initial velocity
for v0=-10:1:10
[xs,ys] = ode45(f,[x_ini,x_end],v0); plot(xs,ys,'b','Linewidth',2)
end
hold off
title('phase potrait plot for a=4')
xlabel('x')
ylabel('y(x)')
grid on

figure(5)
[xs,ys] = ode45(f,[x_ini,1],-5); plot(xs,ys,'b','Linewidth',2)
title('y(x) vs. x plot for a=4 and y(0)=-5')
xlabel('x')
ylabel('y(x)')
grid on


%%Matlab function for direction filed
function dirrfield(f,tval,yval)
% dirfield(f, t1:dt:t2, y1:dy:y2)
%   plot direction field for first order ODE y' = f(t,y)
%   using t-values from t1 to t2 with spacing of dt
%   using y-values from y1 to t2 with spacing of d
%   f is an @ function, or an inline function,
%     or the name of an m-file with quotes.
% Example: y' = -y^2 + t
%   Show direction field for t in [-1,3], y in [-2,2], use
%   spacing of .2 for both t and y:
%   f = @(t,y) -y^2+t
%   dirfield(f, -1:.2:3, -2:.2: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.75;
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])
end

%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
solve in matlab please Draw the phase line for ay-ay(y2-1)(2+y), α > 0 and then using Matlab Problem 1 : graph the solution for different initial conditions. Once you complete that, double the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT