%%Matlab code using RK4 for 1st order differential
equation
clear all
close all
%Program for RK4
%function of 1st order diffrential eqn
f=@(x,y) tan(x);
%step size
h=0.01*pi;
%all final time steps
x(1)=0;y(1)=0; %initial conditions
x_in=x(1); %Initial
x
x_max=pi/4; %Final x
%Runge Kutta 4 iterations
n=(x_max-x_in)/h;
for i=1:n+1
k0=h*f(x(i),y(i));
k1=h*f(x(i)+(1/2)*h,y(i)+(1/2)*k0);
k2=h*f(x(i)+(1/2)*h,y(i)+(1/2)*k1);
k3=h*f(x(i)+h,y(i)+k2);
x(i+1)=x_in+i*h;
y(i+1)=double(y(i)+(1/6)*(k0+2*k1+2*k2+k3));
end
%printing the result
fprintf('\tThe value of y at x=%2.2f for h=
%2.2f is %f\n',x(end),h,double(y(end)))
%function for exact solution
y_ext=@(x) log(abs(sec(x)));
fprintf('\tThe exact value of y at x=%2.2f is
%f\n\n',x_max,y_ext(x_max))
%plotting the function exact and numerical
hold on
plot(x,y)
plot(x,y_ext(x))
%solving using ode45 matlab function
tspan = [0 pi/4];
y0 = 0;
[xx,yy] = ode45(@(x,y) tan(x), tspan, y0);
fprintf('\tThe value of y at x=%2.2f using ode45 is %f\n\n',xx(end),yy(end))
plot(xx,yy,'-o')
xlabel('x')
ylabel('y')
title('x vs. y plot')
legend('RK4 solution','Exact solution','ode45
solution','location','best')
fprintf('Error in RK4 solution with exact solution is
%e.\n',norm(y-y_ext(x)))
fprintf('Error in ode45 solution with exact solution is
%e.\n',norm(yy-y_ext(xx)))
%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%
use matlab only please Problem # 1 P-1 Solve the following initial value problem using a4 order RK scheme: dy dx=tan(x), y(0)= 0.0 - Compare your results by calcudating the error andploting with...
3. Solve the following problem from t 0 to 1 with h-1 using 3rd order RK method: dx dt dy dt bay where (0)-4 and x(0)- 0. 3. Solve the following problem from t 0 to 1 with h-1 using 3rd order RK method: dx dt dy dt bay where (0)-4 and x(0)- 0.
Solve this initial value problem a) 1/2 dy/dx = rad(y+1) cos x, y(pi)=0
Q2 Using Fourth-order RK method, solve the following initial value problem over the interval from t = 0 to 1. Take the initial condition of y(0) = 1 and a step size (h)=0.5. dy = f(t, y) = y t- 1.1 y dt
1. Solve the following initial value problem over the interval from x- 0 to 0.5 with a step size h-0.5 where y(0)-1 dy dx Using Heun method with 2 corrector steps. Calculate g for the corrector steps. Using midpoint method a. b. 1. Solve the following initial value problem over the interval from x- 0 to 0.5 with a step size h-0.5 where y(0)-1 dy dx Using Heun method with 2 corrector steps. Calculate g for the corrector steps. Using...
Solve the initial value problem. dy = x(y-5), y(0) = 7 dx The solution is (Type an implicit solution. Type an equation using x and y as the variables.)
Solve The Given Initial-Value Problem. The DE Is Homogeneous. (X + Yey/X) Dx ? Xey/X Dy = 0, Y(1) = 0
Solve the initial value problem. Vy dx + (x - 7)dy = 0, y(8) = 49 The solution is a (Type an implicit solution. Type an equation using x and y as the variables.)
Solve the initial value problem Please show step by step (c) (x + y)dx - (x - y)dy = 0, y(1) = 0 (d) xy' - y2 in x + y = 0, y(1) = 2
Solve the initial value problem. y dx+(x-7)dy 0, y(8)= 25 The solution is (Type an implicit solution. Type an equation using x and y as the variables.)
Solve the initial value problem. (6+av+x]dx + (8yx? + sin y) dy = 0, y(t) == The solution is (Type an equation using x and y as the variables. Type an implicit solution. Type an exact answer in terms of t.)