Consider the same DE that you solved in Lab 3 that is y y
Consider the same DE that you solved in Lab 3, that is: y = y + 2*cos(x) with initial condition y(0) = -2. Solve it analytically using d solve and get its particular solution y1(x). Create a set of x1 -values between 0 and 2, e.g. by using xl = 0:0.01:2; or by using linspace. Then use the analytic solution to get the corresponding y1 -values. Run euler_app.m with a poor resolution, n=10 subdivisions only. This program prints in the output 10 pairs of x and y values. Put all the x-values in an array called x2 and the y-values in an array called y2. You do that by copying the numbers and pasting them into these arrays. Plot x1 vs, y1 as a continuous blue line. On the same graph, punch the 10 numerical points but paint them a different color, e.g. red. An example of how this is done is shown in the help pages of Matlab. The function that does this has the form: plot (xl, y1, ...., x2, y2, ...., ) Name the axes of the graph as x and y. Also use the command \"title\" to print the analytic particular solution at the top of the graph, as well as your name and section number. The 10:00 class is Section 202. The 11:00 class is Section 203.
Solution
Answer
1.
2.
>>x1 = [0:0.01:-2]
>>f=inline(’y+2*cos(x)’)
>>[x,y] = ode45(f, x1, -2)
