MATLAB HELP 3. Consider the equation y′ = y2 − 3x, where y(0) = 1. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS PROVIDED IN THE PICTURES
a. Use a Euler approximation with a step size of 0.25 to approximate y(2).
b. Use a Runge-Kutta approximation with a step size of 0.25 to approximate y(2).
c. Graph both approximation functions in the same window as a slope field for the differential equation.
d. Find a formula for the actual solution (not by hand). Which is most helpful in understanding the solution: the explicit formula, or the numerical approximation? Explain.
e. Use the explicit formula to compute the exact value of y(2). How close are the Euler and Runge-Kutta approximations?
Please help me form the MATLAB code needed for this question. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS PROVIDED

![Euler approximation function [x,y] = EulerApprox(dydx , xrange,yo,h) xxrange (1):h:xrange (2) x transpose(x): y-zeros (size (](http://img.homeworklib.com/images/4b333736-22db-463c-bd10-ecca8fb37f60.png?x-oss-process=image/resize,w_560)
![Euler approximation function [x,y] = EulerApprox(dydx , xrange,yo,h) xxrange (1):h:xrange (2) x transpose(x): y-zeros (size (](http://img.homeworklib.com/images/6c35f76e-324d-46d2-9d3d-d491d9eba2a2.png?x-oss-process=image/resize,w_560)
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE TTHERE TO HELP YOU..ALL THE BEST..
AS FOR GIVEN DATA.
%%Matlab code for Euler's forward and Rk4
method
clear all
close all
%Answering question a.
%---------------------%
%Program for Euler
%function for Euler equation solution
syms x y
f(x,y)=y^2-3*x;
%Euler steps for h and x_end
%Initial values
x0=0;
y0=1;
%step size
h=0.25;
%x end value
xend=2;
xn=x0:h:xend;
% Euler steps
y_result1(1)=y0;
x_result1(1)=x0;
%Loop for Euler Steps
for i=1:length(xn)-1
x_result1(i+1)= x_result1(i)+h;
y_result1(i+1)=y_result1(i)+h*double(f(x_result1(i),y_result1(i)));
end
%printing the result for Euler
fprintf('\tThe approximate solution using Euler method at x=%d for
h=%0.2f is %f\n',xend,h,y_result1(end))
%Answering question b.
%---------------------%
%Program for RK4
%function for RK4 equation solution
syms x y
f(x,y)=y^2-3*x;
%RK4 steps for h and x_end
%Initial values
x0=0;
y0=1;
%x end value
xend=2;
xn=x0:h:xend;
% RK4 steps
y_result2(1)=y0;
x_result2(1)=x0;
%Runge Kutta 4 iterations
n=(xend-x0)/h;
for i=1:n
k0=h*f(x_result2(i),y_result2(i));
k1=h*f(x_result2(i)+(1/2)*h,y_result2(i)+(1/2)*k0);
k2=h*f(x_result2(i)+(1/2)*h,y_result2(i)+(1/2)*k1);
k3=h*f(x_result2(i)+h,y_result2(i)+k2);
x_result2(i+1)=x_result2(i)+h;
y_result2(i+1)=double(y_result2(i)+(1/6)*(k0+2*k1+2*k2+k3));
end
%printing the result for RK4
fprintf('\tThe approximate solution using RK4 method at x=%d for
h=%0.2f is %f\n',xend,h,y_result2(end))
%Answering question c.
%---------------------%
hold on
%plotting the solutions for Euler and RK4
plot(x_result1,y_result1,'b')
plot(x_result2,y_result2,'g')
title('Solution plot for differential equation')
xlabel('x')
ylabel('y')
%slope field calculation
funn=@(x,y) y.^2-3.*x;
xx=0:.2:2; yy=-3:.2:3;
[X,Y]=meshgrid(xx,yy);
slopes=funn(X,Y);
dy=slopes./sqrt(1+slopes.^2);
dx=ones(size(dy))./sqrt(1+slopes.^2);
h=quiver(X,Y,dx,dy,.5,'color','r');
set(h,'maxheadsize',0.1)
legend('Euler solution','RK4 solution','Slope
field','location','best')
%Answering question d.
%---------------------%
%Finding exact solution using dsolve
syms y(x)
eqn=diff(y,x)==y^2-3*x;
cond=y(0)==1;
y_result3(x)=dsolve(eqn,cond);
%printing exact solution
fprintf('\tThe exact solution using dsolve at x=%d is
%f\n',xend,y_result3(xend))
fprintf('The expression for Exact solution\n')
disp(y_result3(x))
fprintf('Numerical solution are better to understand than exact
solution.\n')
%Answering question e.
%---------------------%
err1=double((abs(y_result3(xend)-y_result1(end))/y_result3(xend))*100);
err2=double((abs(y_result3(xend)-y_result2(end))/y_result3(xend))*100);
fprintf('For step size h=%2.2f.\n',h)
fprintf('\tThe percentage relative error for solving differential
eqn using Euler method is %f\n',abs(err1))
fprintf('\tThe percentage relative error for solving differential
eqn using RK4 method is %f\n',abs(err2))
I HOPE YOU UNDERSTAND..
PLS RATE THUMBS UP..ITS HELPS ME ALOT..
THANK YOU...!!
MATLAB HELP 3. Consider the equation y′ = y2 − 3x, where y(0) = 1. USE THE EULER AND RUNGE-KUTTA APPROXIMATION SCRIPTS...
step Consider the IVP y = 1 + y?, y(0) = 0 a. Use the Runge-Kutta Method with step size 0.1 to approximate y(0.2) b. Find the error between the analytic solution and the approximate solution at each step
5. Consider the following second order explicit Runge-Kutta scheme: k=hf(an, Yn) k2 = hf(2, +h, yn +ki) Yn+k2. Yn+1 (a) Express the following ordinary differential equation and initial conditions as a sys- tem of first order equations: y(1)=1, /(1) 3. (b) Use the second order explicit Runge-Kutta scheme with one step to compute an approximation to y(1.2).
5. Consider the following second order explicit Runge-Kutta scheme: k=hf(an, Yn) k2 = hf(2, +h, yn +ki) Yn+k2. Yn+1 (a) Express the following...
(e) Consider the Runge-Kutta method in solving the following first order ODE: dy First, using Taylor series expansion, we have the following approximation of y evaluated at the time step n+1 as a function of y at the time step n: where h is the size of the time step. The fourth order Runge-Kutta method assumes the following form where the following approximations can be made at various iterations: )sh+รู้: ,f(t.ta, ),. Note that the first term is evaluated at...
Question 12 (3 marks) Special Attempt 2 A system of two first order differential equations can be written as 0 dr A second order explicit Runge-Kutta scheme for the system of two first order equations is 1hg(n,un,vn), un+1 Consider the following second order differential equation d2 0cy-6, with v(1)-1 and y'()-o Use the Runge-kutta scheme to find an approximate solution of the second order differential equation, at x = 1.2, if the step size h Maintain at least eight decimal...
answer fast please
2. For y'=(1+4x)/7, and y(0)=0.5 a) Use the Euler method to integrate from x=0 to 0.5 with h=0.25. (10 pts) b) Use the 4th order Runge-Kutta method to numerically integrate the equation above for x=0 to 0.25 with h=0.25. (15 pts) Euler Method 91+1 = y + oh where $ = = f(ty 4th Order Runge-Kutta Method 2+1= ++ where $ = (ką + 2k2 + 2kg + ks) ky = f(tuy) k2 = f(t+1,91 +{kxh) kz...
(3) Consider the expressions (a) Write down the Runge-Kutta method for the numerical solution to a differential equation Oy (b) Show that if f is independent of y, i.e. f(x, y) g(x) for some g, then the Runge-Kutta method on the interval n n + h] becomes Simpson's Rule for the numerical approximation of the integral g(x) dr. In this case, what is the global error, in terms of O(hk) for some k>0?
(3) Consider the expressions (a) Write down...
///MATLAB/// Consider the differential equation over the
interval [0,4] with initial condition y(0)=0.
3. Consider the differential equation n y' = (t3 - t2 -7t - 5)e over the interval [0,4 with initial condition y(0) = 0. (a) Plot the approximate solutions obtained using the methods of Euler, midpoint and the classic fourth order Runge Kutta with n 40 superimposed over the exact solution in the same figure. To plot multiple curves in the same figure, make use of the...
Matlab & Differential Equations Help Needed
I need help with this Matlab project for differential equations.
I've got 0 experience with Matlab other than a much easier project
I did in another class a few semesters ago. All we've been given is
this piece of paper and some sample code. I don't even know how to
begin to approach this. I don't know how to use Matlab at all and I
barely can do this material.
Here's the handout:
Here's...
1
with 5. Consider the differential equation y, f(x,y) with initial condition y(zo) = yo. Show that, zi = zo +h, the solution at x1 can be obtained with an er ror O(h3) by the formula In other words, this formula describes a Runge-Kutta method of order 2.
with 5. Consider the differential equation y, f(x,y) with initial condition y(zo) = yo. Show that, zi = zo +h, the solution at x1 can be obtained with an er ror O(h3)...
Solve the ordinary differential equation below over the interval 0 sts 2s using two different methods: the Euler method and the second-order Runge-Kutta method (midpoint version). Begin by writing the state space representation of the equation. Use a time step of 1 s, and place a box around the values of x and x at t- 2 s obtained using each method. Show your work. 20d's +5dr +20x = 0 dt d x(0) = 1, x'(0) = 1
Solve the...