Question

In: Advanced Math

Differential Equations 1. Create a direction field for y 0 = y − y 2 ....

Differential Equations

1. Create a direction field for y 0 = y − y 2 .

(a) You should find any equilibrium solutions by hand and at least a few other solutions. Feel free to make a direction field with some piece of technology and share a picture of it.

(b) Find at least a few solution curves and describe the behavior of y as x → ∞, for different ranges of initial values y(x0) = y0.

(c) Use your direction field to approximate the value of y(0.5) if the initial condition is y(0) = 0.5.

(d) Use Euler’s method with h = 0.1 to approximate y(0.5) when the initial condition is y(0) = 0.5.

(e) Bonus: Find the analytical solution to this differential equation with initial condition y(0) = 0.5 and then find the exact value of y, what is your percent error from your Euler method approximation?

Solutions

Expert Solution

%Matlab code for direction field and plot
clear all
close all

%function for which direction field have to do
f=@(t,y) y-y.^2;
fprintf('function for which direction field have to make f(y)=')
disp(f)
%Plotting Direction field
figure(1)
dirrfield(f,0:.25:5,-2:.25:4)
hold on
t_ini=0;
t_end=5;
%plot for different initial velocity
for v0=-2:0.5:4
[ts,ys] = ode45(f,[t_ini,t_end],v0); plot(ts,ys,'b','Linewidth',2)
end

hold off
title('phase potrait plot')
xlabel('time in sec.')
ylabel('y(t) ')

syms y(t) y0
eqn = diff(y,t) == y-y.^2;
cond = [y(0)==y0];
ySol(t) = dsolve(eqn,cond);
fprintf('Exact solution for initial condition y(0)=y0, is ')
disp(ySol)

fprintf('For y(0)=0.5, y(0.5)=0.62 \n')
fprintf('Solution using Euler method\n')
[y1_result,t_result] = euler_method(f,0.5,0,0.5,0.1);
%Exact solution for y(0)=0.5
syms y(t)
eqn = diff(y,t) == y-y.^2;
cond = [y(0)==0.5];
yS(t) = dsolve(eqn,cond);
fprintf('Exact solution for initial condition y(0)=0.5, is ')
disp(yS)

for i=1:6
    err=abs(y1_result(i)-yS(t_result(i)))/yS(t_result(i));
    fprintf('\tExact solution at t=%2.2f is %f with error=%f\n',t_result(i),y1_result(i),err)
end

%%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 dy
%
%   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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Matlab code for Euler's forward
function [y1_result,t_result] = euler_method(f,y0,t0,tend,h)
%function for Euler equation solution
  
    %all step size
    N=(tend-t0)/h;
    %Initial values

    %t end values
    tn=t0:h:tend;
    % Euler steps
    y1_result(1)=y0;
    t_result(1)=t0;
    fprintf('\nFor step size %2.2f\n',h)
    for i=1:length(tn)-1
        t_result(i+1)= t_result(i)+h;
        y1_result(i+1)=y1_result(i)+h*double(f(t_result(i),y1_result(i)));
        fprintf('\tAt t=%2.2f y(%2.2f)=%f\n',t_result(i+1),t_result(i+1),y1_result(i+1))
    end
end


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


Related Solutions

using series to solve differential equations using series to solve differential equations 1.) y’’-(e^5x)y’+xy=0,y(0)=2,y’(0)=1
using series to solve differential equations using series to solve differential equations 1.) y’’-(e^5x)y’+xy=0,y(0)=2,y’(0)=1
(Differential Equations) Consider the differential equation xy’-x4y3+y=0 Verify that the function y = (Cx2-x4)-1/2 is a...
(Differential Equations) Consider the differential equation xy’-x4y3+y=0 Verify that the function y = (Cx2-x4)-1/2 is a solution of the differential equation where C is an arbitrary constant. Find the value of C such that y(-1) = 1. State the solution of the initial value problem. State the interval of existence.
Solve the differential equation y''+y'-2y=3, y(0)=2, y'(0) = -1
Solve the differential equation y''+y'-2y=3, y(0)=2, y'(0) = -1
Solve the following differential equations: 1.) y"(x)+ y(x)=4e^x ; y(0)=0, y'(0)=0 2.) x"(t)+3x'(t)+2x(t)=4t^2 ; x(0)=0, x'(0)=0
Solve the following differential equations: 1.) y"(x)+ y(x)=4e^x ; y(0)=0, y'(0)=0 2.) x"(t)+3x'(t)+2x(t)=4t^2 ; x(0)=0, x'(0)=0
Differential Equations Use a series solution to solve the IVP . y′′−4y= 0 y(0) = 3...
Differential Equations Use a series solution to solve the IVP . y′′−4y= 0 y(0) = 3 y′(0) = 5. (Your answer will use one or more series.)
y''+xy'+(2x^2+1)y=0 Use power series to find at least four terms of the following differential equations
y''+xy'+(2x^2+1)y=0 Use power series to find at least four terms of the following differential equations
Solve the following differential equations: 1. x"(t)+ x(t)=6sin(2t) ; x(0)=3, x'(0)=1 2.y"(t)- y(t)=4cos(t) ; y(0)+0 ,...
Solve the following differential equations: 1. x"(t)+ x(t)=6sin(2t) ; x(0)=3, x'(0)=1 2.y"(t)- y(t)=4cos(t) ; y(0)+0 , y'(0)=1
Find a solution of the following differential equations satisfying the given initial conditions y''+y'+y=x2 , y(0)=1,...
Find a solution of the following differential equations satisfying the given initial conditions y''+y'+y=x2 , y(0)=1, y'(0)=1
Solve the following differential equations: 1.) y"(t)- 6 y'(t)+9 y(t)=6t^2e^(3t) ; y(0)=y'(0)=0 2.)x"(t)+4x(t)=t +4 ; x(0)=1...
Solve the following differential equations: 1.) y"(t)- 6 y'(t)+9 y(t)=6t^2e^(3t) ; y(0)=y'(0)=0 2.)x"(t)+4x(t)=t +4 ; x(0)=1 , x'(0)=0
Solve the following first order differential equations: (a) 2/?^ ???/?? = 4?^2? ; ?(0) = −1/...
Solve the following first order differential equations: (a) 2/?^ ???/?? = 4?^2? ; ?(0) = −1/ 3 (b) ??/?? + ? = ? ; ?(0) = 5 (c) ??/?? + ? /? = ? 3 ; ? ( 1/2 ) = 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT