Need help. Only intelligent people. Anyone good with Matlab??
what type of math
Consider the initial value problem dy dt = cos(t)y(t) + cos(t) y(0) = 1 a.) Give the solution to the initial value problem. b.) Find a time step h that would evenly divide the interval [0; 2] into N subintervals and guarantee a local truncation error of at most 0.01 for the Euler method on the same interval. Use this time step to apply the Euler method and the Improved Euler method to this initial value problem over the interval [0; 2] and plot the actual solution along with the two approximated solutions.
lolol
math like this is horrible and not really useful...
Intervals are [0. 2*pi]
is it the first ODE?
yes
Well... \[\Large \frac{dy}{dt} = \cos(t)y(t) + \cos(t)\] right?
In that case, this equation is separable: \[\Large \frac{\color{blue}{dy}}{\color{red}{dt}}=(y+1)\cos(t)\]
\[\Large \frac{\color{blue}{dy}}{y+1}= \cos(t) \color{red}{dt}\]and then integrate both sides:
the question looking for a numerical method
the forward euler scheme for \[\large \frac{dy}{dx}=f(x,y),\qquad y(0)=y_0\]is \[ \large\hat y_{j+1}=\hat y_j+hf(x_j,\hat y_j)\] where the step size is \( h\)
however the computer will prefer it if you set the initial value first \[\hat y_1=y_0\] then ``` for j=2:N ``` \[\large \large\hat y_{j}=\hat y_{j-1}+h f(x_{j-1},\hat y_{j-1})\] ``` end ```
the forward euler scheme for \[\large \frac{dy}{dx}=f(x,y),\qquad y(0)=y_0\]is \[ \large\hat y_{j+1}=\hat y_j+hf(x_j,\hat y_j)\] where the step size is \( h\)
``` function [] = DE (h) %% Parameters % t0 = 0; % min tM = 2; % max N ; % number of subintervals %% this should be a function of h,t,tMax % t ; % domain %% this should be a function t0,tMax,N % y0 = 1; % initial value %% Exact Values % y ; %% find the exact value using separation of variables, as terenzreignz started % %% Approx Values % yHat = zeros(1,N); % empty yHat yHat(1) = y0; % yHat(0) for j=2:N yHat(j) ; %% = yHat +h.*f(x_j-1,yHat_j-1) % end %% Graph % figure(2); clf; grid hold on plot(t, y, 'k') plot(t, yHat,'b') hold off clear ```
Join our real-time social learning platform and learn together with your friends!