%Matlab code for Euler and Heun method
clear all
close all
%all initial conditions
t_in=0; t_end=1;
P_in=1;
a=1; Pm=10;
%Function for exact solution
C=(1/(Pm-1));
P_ext=@(t) (Pm*C*exp(a*Pm*t))/(1+C*exp(Pm*a*t));
fprintf('Displaying exact solution\n')
disp(P_ext)
fprintf('Here value of C=%f\n\n',C)
%loop for step size
for k=1:3
h=10^-k;
[P_euler,t_elr]=euler(h,P_in,t_in,t_end);
[P_heun,t_hnn]=heun(h,P_in,t_in,t_end);
fprintf('For step size h=%f\n',h)
fprintf('\tUsing Euler method at t=%f value of
P(%f) is %f.\n',t_elr(end),t_elr(end),P_euler(end))
fprintf('\tUsing Heun method at t=%f value of
P(%f) is %f.\n',t_hnn(end),t_hnn(end),P_heun(end))
fprintf('\tExact solution at t=%f is
%f.\n',t_end,P_ext(t_end))
fprintf('\tError in Euler method is
%e.\n',abs(P_ext(t_end)-P_euler(end)))
fprintf('\tError in Heun method is
%e.\n\n',abs(P_ext(t_end)-P_heun(end)))
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function for euler method
function [P1,t]=euler(h,P_in,t_in,t_end)
%all parameter values
a=1; Pm=10;
%function (i)
f=@(t,P) a*P*(Pm-P);
%initial conditions
t(1)=t_in;P1(1)=P_in;
t_in=t(1);
%Initial t
t_max=t_end;
%Final t
n=(t_max-t_in)/h; %number of steps
%Runge Kutta 4 iterations
for i=1:n
t(i+1)=t_in+i*h;
P1(i+1)=double(P1(i)+h*(f(t(i),P1(i))));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function for heun method
function [P1,t]=heun(h,P_in,t_in,t_end)
%all parameter values
a=1; Pm=10;
%function (i)
f=@(t,P) a*P*(Pm-P);
%initial conditions
t(1)=t_in;P1(1)=P_in;
t_max=t_end;
%Final t
tn=t_in:h:t_max;
%Runge Kutta 1 iterations
for i=1:length(tn)-1
t(i+1)= t(i)+h;
m1=double(f(t,P1(i)));
m2=double(f((t+h),(P1(i)+h*m1)));
P1(i+1)=P1(i)+double(h*((m1+m2)/2));
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
choosing C to make P(t) match P(0) at t = 0. Compute the maximum error over 0 ≤ t ≤ 1 for each solution you obtain. How do the errors change with h for the two methods? dP aP (PM-P). With a 1 and...
I. Use Euler's method with step size h = 0.1 to numerically solve the initial value problem y,--2ty+y2, y(0) 1 on the interval 0 < t 2. Compare your approximations with the exact solution. I. Use Euler's method with step size h = 0.1 to numerically solve the initial value problem y,--2ty+y2, y(0) 1 on the interval 0
Euler's Method C Get Homework Help With Sy solve for C, 2--(9e (1.71(0)+C) CUse Euler's Method To Make A T x + Cheg X x https://www.webassign.net/web/Student/Assignment-Responses/last?dep-21259636 Question Details LarCalc11 6 R014 My Notes k Your Teacher Use Euler's Method to make a table of values r the approximate solution of the differential equation with the specified initial value. Use n steps of size h. (Round your answers to four decimal places.) y' 7x-4y, y(0)-4, n-10, h-0.1 3 4 5 6...
Solve using Matlab Use the forward Euler method, Vi+,-Vi+(4+1-tinti ,Vi) for i= 0,1,2, , taking yo y(to) to be the initial condition, to approximate the solution at t-2 of the IVP y'=y-t2 + 1, 0-t-2, y(0) = 0.5. Use N = 2k, k = 1, 2, , 20 equispaced time steps (so to = 0 and tN-1 = 2). Make a convergence plot, computing the error by comparing with the exact solution, y: t1)2 -exp(t)/2, and plotting the error as...
Problem Thre: 125 points) Consider the following initial value problem: dy-2y+ t The y(0) -1 ea dt ical solution of the differential equation is: y(O)(2-2t+3e-2+1)y fr exoc the differential equation numerically over the interval 0 s i s 2.0 and a step size h At 0.5.A Apply the following Runge-Kutta methods for each of the step. (show your calculations) i. [0.0 0.5: Euler method ii. [0.5 1.0]: Heun method. ii. [1.0 1.5): Midpoint method. iv. [1.5 2.0): 4h RK method...
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...
[7] 1. Consider the initial value problem (IVP) y′(t) = −y(t), y(0) = 1 The solution to this IVP is y(t) = e−t [1] i) Implement Euler’s method and generate an approximate solution of this IVP over the interval [0,2], using stepsize h = 0.1. (The Google sheet posted on LEARN is set up to carry out precisely this task.) Report the resulting approximation of the value y(2). [1] ii) Repeat part (ii), but use stepsize h = 0.05. Describe...
Q3p please with mathlab. 1) The growth of populations of organisms has many engineering and scientific applications. One of the simplest models assumes that the rate of change of the population p is proportional to the existing population at any time t: dp/dt = kp where k, is the growth rate. The world population in millions from 1950 through 2000 was 1950 1959 1960 1965 1970 1975 1980 1989 1990 19952000 P25602780 3040 3350 3710 4090 4450 4850 528056906080 ....
s method and h-0 5 TTOP Tor the value at t 2.0 obtained by Euler's method Report results to two decimal places 5. The population of a certain type of bacteria, kept in a Petri dish at a constant 25 C,changes according to the Limited Growth Model. An initial population of 10 million bacteria increases to 15 million carrying capacity, M, of this system is 40 million bacteria. (Recall: for this model the rate of population with respect to time,...
6. Consider the Cauchy problem for the advection equation, u +cu0, where c>0 a) Expand u(z,t + k) in a Taylor series up to O(k3) terms. Then use the advection equation to obtain c2k2 uzz(x, t) + O(k"). u(z, t + k) u(x, t) _ cku(x, t) +- b) Replace u and ur by centered difference approximations to obtain the explicit scheme This is the Lax-Wendroff method. It is von Neumann stable for 0 < 8 < 1 and it...
I need help with these! 3. (1 point) a) Compute the general solution of the differential equation y"5 12y" 0 b) Determine the test function Y (t) with the fewest terms to be used to obtain a particular solution of the following equation via the method if undetermined coefficients. Do not attempt to determine the coefficients.5y 12y"2 10e-tesin(V3t) Spring 2011) 4. (1 point) Compute the general solution of the following differential equations dz dy dt ii)(1y iv) (z cos(y) +...