Question
MATLAB ASSINGMENT Consider the same DE that appears below; y' = y + 2*cos(x) with initial condition y(0) = -2. 1. Solve it analytically using
MATLAB ASSINGMENT
Consider the same DE that appears below;
y' = y + 2*cos(x) with initial condition y(0) = -2.
1. Solve it analytically using "dsolve" and get its particular solution y1(x).
2. Create a set of x1-values between 0 and 2, e.g. by using x1 = 0:0.01:2; or by using linspace. Then use the analytic solution to get the corresponding y1-values.
3. Run euler_app.m (in Lab 3) with a poor resolution, use 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.
4. 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 ( x1, y1, ......., x2, y2, ....... )
5. 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 names.
MATLAB Project 1 Current This MATLAB code uses Euler's method to solve numerically the IVP dy/dx = 2cosx + y , y(0)=-2 in the x-interval [0, 2]. The number of subintervals is set to n=10, but it can be incrased for more accuracy. Next week you will work at the computer lab (or anywhere else you like) without me. If you like, you can even go to the lab at any other time or use Matlab on your home computer if you have a version. Your goal will be to complete a graph that displays various pieces of information. $ In the output, MATLAB holds two matrices x, y with the values of the x-coordinates and the corresponding values of the function y(x). Here is a description of the 1st Matlab project: a = 0; b = 2; yo = -2; n = 10; Consider the same DE that appears in Lab 3, that is: y' = y + 2*cos(x) with initial condition y(0) = -2. % Print the x - y results 1. Solve it analytically using "dsolve" and get its particular solution y1(x). | for i=1:n+1 fprintf('%f end %f ', x(i), y(i)) 2. Create a set of x1-values between 0 and 2, e.g. by using x1 = 0:0.01:2; or by using linspace. Then use the analytic solution to get the corresponding y1-values. 3. Run euler_app.m (in Lab 3) with a poor resolution, use 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. 4. 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 (x1, y1, ....., x2, y2, ......) Command Window fx >> 5. 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 namesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started