Question: User Matlab or Python for answer. Please don't answer from Chegg that has been wrong question is completely different please check and then answer my

User Matlab or Python for answer. Please don't answer from Chegg that has been wrong question is completely different please check and then answer my question I will also provide you refer below. Please don't copy or past answer that's on Chegg that wrong. If you don't now answer don't try to answer this question.




= = = = = e Using the RK4 method, give the numerical approximation for the IVP: y' ty; y(0) = e; with a step size of h 0.5 for the point at t 20. How does this compare to Euler's Method (e.g. simply using the k values to approximate this ODE)?. The exact solution to the IVP above is y(t) = t? /2+1. In a single figure, plot the results of RK4, Euler methods and the exact function (thus, your plot should contain 3 lines). To show the full Y-range, the Y-axis should be plotted using a log-scale, however the X-axis should remain linear. To do this, type set(gca, YScale,log) on the line below that used to create the plot. Make sure that your figure has a legend that describes what each line corresponds to. = Suppose we have the initial value problem (IVP): y = f(t,y); y(to) = =yo where y is the time derivative of the function y, i.e. j = d y is an unknown function of time t, which we would like to approximate; we are told that y, the rate at which y changes, is a function of t and of y itself. At the initial time to the corresponding y value is yo. The function f and the data to, Yo are given. We want to 'step' through the function to find a numerical approximation at some time, t. Choose a step size, h, such that h > 0 and define: Yn+1 = yn + b (ki + 2k2 + 2k3 + ka) tn+1=tn+h for n = 0,1,2,3,..., using: = k = f(tn, yn) k2 = = f(tn + 3x Yn + biki) k3 = f(tn + , Yn + k2) k4 = f(tn + h, yn + hk3) Here Yn+1 is the RK4 approximation of y(tn+1), and the next value (yn+1) is determined by the present value (yn) plus the weighted average of four increments, where each increment is the product of the size of the interval, h, and an estimated slope specified by function f on the right-hand side of the differential equation. ki is the increment based on the slope at the beginning of the interval, using y. k2 is the increment based on the slope at the midpoint of the interval, using y + ki; ky is again the increment based on the slope at the midpoint, but now using y + ika; k is the increment based on the slope at the end of the interval, using y + hk3. 2 Example We want to find y(1.5) using RK4 method with a step size of 0.5 for the IVP: y' = -2xy?; y(0) = 1 Note: in this example, y is a function of the independent variable x. We need to find the k-values for x = 0.5 to obtain an approximation for y(0.5) and then again find the k-values for x = 1.0. We then use our approximation of y(0.5) and the k-values at x = 1.0 to get an approximation of y(1.0). We then do this again for x = 1.5, see below. 2.1 Solution 2.1.1 x=0 This is our initial value, so yo = 1, X, = 0 2.1.2 x=0.5 Yo * ki = f(xo, yo) = -2 * *, *y2 = -2*() * 12 = 0 k2 = f(%. + , 4. + k) = )= -2 + (z + 3) + (+ 5 + 0)2 = -2 * (0.25) + 12 = -0.5 k3 = f(xo + , yo + k2) = 2 + (x.+) * (40+ }k2)2 = 2 * (0.25) * (0.875)2 = -0.3828... k4 = f(xo+h,yo+hk3) = 2*(xo+h)*(yo+hk3)2 = 2*(0.5)*(0.80859375)2 = -0.6538... Therefore: * = = Y1 = yo+(k +2k2+2k3+ka) = 1+0.5 *(0+2*(-0.5)+2+(-0.3828...) 0.6538...) = 0.7984... And we already knew 21 = 0.5 2.1.3 =1 As you can see from above, doing this by hand is not fun. So I have listed the k-values below, use these to check that your algorithm is working properly: ki = -0.6374... k2 = -0.6125... k3 = -0.6245... k4 = -0.4726... Therefore: y2 = y1 + b (ki + 2k2 + 2k3 +ka) = 0.7984... + 0.5 * (-0.6374... +2*(-0.6125...) + 2 * (-0.6245..) 0.4726...) = 0.4997... 2.1.4 = 1.5 ki = -0.4994... k2 = -0.3513... k3 = -0.4241... k4 = -0.2482... Therefore: Y3 = y2 + " (ki + 2k2 + 2k3 + ka) = 0.4997... + 05 * (-0.4994... +2* (-0.3513...) + 2 * (-0.4241..) 0.2482...) = 0.3082... * 2.2 Exact Solution Since the IVP y = -2xy?; y(0) = 1 is relatively simple, we can compute the exact solution using calculus. We start by rewrititng the equation: -2xy? = dc = -2xdx so = 2xdx -=-+C Using the IVP, we see that C = -1. Solving for y, yields: y= = 2211 We are interested in y(x = 1.5). Substituting the above gives the exact solution of y(1.5) = 0.3076.... = 3 Lab component You are to create a script in Matlab that will estimate the solution for an ordinary differ- ential equation using the RK4 method outlined above. Below is some code to help you get started: %RK4 clearvars %always helpful to have so matlab doesn't remember past things! f = @(t,y) (-2*t*y*2); %define function, e.g your y' %the initial conditions yo = 1; t0 = 0; Q_val = 1; %define query point h = .5; %step size iterationN = round((Q_val-t0)/step); %helpful if your IVP is not at t=0. yi = zeros(iterationN+1, 1); %initalize empty vector for y values ti = zeros(iterationN+1,1); %initialize empty vector for t values %placing IVP into yi and xi vectors yi(1) = yo; ti(1) = to; From here you need to implement a for loop to approximate the solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
