Question

In: Computer Science

Write Matlab code that solves (dy/dt)= yt^3 - 1.5y on the interval t= 0 to 2...

Write Matlab code that solves (dy/dt)= yt^3 - 1.5y on the interval t= 0 to 2 where y(0) = 1. As well as (dy/dx) = (1+4x)y^.5 on the interval x = 0 to 1 where y(0) = 1 using Matlab functions that solve any ODE using the below methods

  • Midpoint Method
  • Huens Method

Functions need to call:

  • Error desired
  • number of iterations
  • Step size
  • Initial Interval
  • y(0)

And return

  • Result
  • Error of that result

Solutions

Expert Solution

`Hey,

Note: In case of any queries, just comment in box I would be very happy to assist all your queries

clc
clear all
close all
f=@(t,y) y*t^3-1.5*y;
g=@(x,y) (1+4*x)*y^(0.5);
disp('Equation 1 using heun');
[T,Y]=heun(f,[0,2],1,0.05)
plot(T,Y);
title('Equation 1 plot heun');
disp('Equation 2 using heun');
[X,Y]=heun(g,[0,2],1,0.05)
figure;
plot(X,Y);
title('Equation 2 plot heun');
figure;
disp('Equation 1 using midpoint');
[T,Y]=midpoint(f,[0,2],1,0.05)
plot(T,Y);
title('Equation 1 plot midpoint');
disp('Equation 2 using midpoint');
[X,Y]=midpoint(g,[0,1],1,0.05)
figure;
plot(X,Y);
title('Equation 2 plot midpoint');
function [t,y] = midpoint(f,tspan,ya,h)
a=tspan(1);
b=tspan(2);
n = floor((b - a) / h);
halfh = h / 2;
y(1,:) = ya;
t(1) = a;
for i = 1 : n
t(i+1) = t(i) + h;
z = y(i,:) + halfh * f(t(i),y(i,:));
y(i+1,:) = y(i,:) + h * f(t(i)+halfh,z);
end
end
function [t,y] = heun(f,tspan,ya,h)
a=tspan(1);
b=tspan(2);
n = floor((b - a) / h);
halfh = h / 2;
y(1,:) = ya;
t(1) = a;
for i = 1 : n
t(i+1) = t(i) + h;
g = f(t(i),y(i,:));
z = y(i,:) + h * g;
y(i+1,:) = y(i,:) + halfh * ( g + f(t(i+1),z) );
end
end

Kindly revert for any queries

Thanks.


Related Solutions

Write Matlab code that solves (dy/dt)= yt^3 - 1.5y on the interval t= 0 to 2...
Write Matlab code that solves (dy/dt)= yt^3 - 1.5y on the interval t= 0 to 2 where y(0) = 1. As well as (dy/dx) = (1+4x)y^.5 on the interval x = 0 to 1 where y(0) = 1 using Matlab functions that solve any ODE using the below method Runge-Kutta Method 4th Order Functions need to call: Error desired number of iterations Step size Initial Interval y(0) And return Result Error of that result
Consider the following initial value problem dy/dt = 3 − 2*t − 0.5*y, y (0) =...
Consider the following initial value problem dy/dt = 3 − 2*t − 0.5*y, y (0) = 1 We would like to find an approximation solution with the step size h = 0.05. What is the approximation of y(0.1)?
Use a LaPlace transform to solve d^2x/dt^2+dx/dt+dy/dt=0 d^2y/dt^2+dy/dt-4dy/dt=0 x(0)=1,x'(0)=0 y(0)=-1,y'(0)=5
Use a LaPlace transform to solve d^2x/dt^2+dx/dt+dy/dt=0 d^2y/dt^2+dy/dt-4dy/dt=0 x(0)=1,x'(0)=0 y(0)=-1,y'(0)=5
Assume x and y are functions of t. Evaluate dy/dt with 4xy-5x+6y^3=-126, with dx/dt=-18, and x=6,y=-2...
Assume x and y are functions of t. Evaluate dy/dt with 4xy-5x+6y^3=-126, with dx/dt=-18, and x=6,y=-2 A retail store estimates that weekly sales and weekly advertising costs x​ are related by s=50,000-30,000e^-0.0004x. The current weekly advertising costs are ​$2,500​, and these costs are increasing at a rate of ​$400 per week. Find the current rate of change of sales per week. Use implicit differentiation to find y’ for the equation below and then evaluate y’ at the indicated point, (-4,4)....
Solve the following initial value problems (1) dy/dt = t + y y(0) = 1 so...
Solve the following initial value problems (1) dy/dt = t + y y(0) = 1 so y(t) = (2)  dy/dt = ty y(0) = 1 so y(t) =
Consider the system modeled by the differential equation dy/dt - y = t with initial condition y(0) = 1
Consider the system modeled by the differential equation                               dy/dt - y = t    with initial condition y(0) = 1 the exact solution is given by y(t) = 2et − t − 1   Note, the differential equation dy/dt - y =t can be written as                                               dy/dt = t + y using Euler’s approximation of dy/dt = (y(t + Dt) – y(t))/ Dt                               (y(t + Dt) – y(t))/ Dt = (t + y)                                y(t + Dt) =...
dx dt =ax+by dy dt =−x − y, 2. As the values of a and b...
dx dt =ax+by dy dt =−x − y, 2. As the values of a and b are changed so that the point (a,b) moves from one region to another, the type of the linear system changes, that is, a bifurcation occurs. Which of these bifurcations is important for the long-term behavior of solutions? Which of these bifurcations corresponds to a dramatic change in the phase plane or the x(t)and y(t)-graphs?
Solve the system of equation by method of elimination. dx/dt + x−5y = 0, 4x +dy/dt+...
Solve the system of equation by method of elimination. dx/dt + x−5y = 0, 4x +dy/dt+ 5y = 0, x(0) = −1, y(0) = 2.
Solve the given initial-value problem. dx/dt = y − 1 dy/dt = −6x + 2y x(0)...
Solve the given initial-value problem. dx/dt = y − 1 dy/dt = −6x + 2y x(0) = 0, y(0) = 0
d^2y/dx^2 − dy/dx − 3/4 y = 0, y(0) = 1, dy/dx(0) = 0, Convert the...
d^2y/dx^2 − dy/dx − 3/4 y = 0, y(0) = 1, dy/dx(0) = 0, Convert the initial value problem into a set of two coupled first-order initial value problems and find the exact solution to the differential equatiion
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT