Euler’s Method and Introduction to MATLAB • Start MATLAB • Inline Commands: You can type commands directly into the command...

80.2K

Verified Solution

Question

Advance Math

Euler’s Methodand Introduction to MATLAB

•Start MATLAB

•Inline Commands: You can type commands directly into the command window: Type andexpression and then hit enter to evaluate the expression. Forexample:

>> 2+2

If you want to suppress the output of a command follow itwith ‘;”.  Forexample >>2+2;

Practice evaluating a few expressions in the command window. (InMATLAB multiplicationis represented by * so 3*2=6).

•Variables and Vectors:You can define variables in the command window. For example, to set thevalue of the variablex equal to 2 just type >>x=2and hit enter.Notice that the variable x now appears in your workspace on the far right handside.

Variables can be vectors. For example >>x=[1 2 3] creates a row vectorwith three components: x(1)=1,x(2)=2, and x(3)=3. Try it.  Whathappens when you set x=[1;2;3]?

•Inline Functions: You can create functions in the command window. We will createfunctionsof two variables.(Later these functions will represent the derivative of another function.)For example to create a function g(x,y)=-15ytype g=@(x,y)(-15*y) and press enter.

Now that you have created the functiong(x,y)you can evaluate it at different x and y values.For example,to compute g(1,2),just type: >>g(1,2) and hit enter. Also computeg(2,2).Why is g(1,2)=g(2,2)?

•Functions in M files: MATLAB functions can also be saved as m files. Download euler_method.m from D2L and save it to your MATLAB directory.

When you open the file euler_method.myou will see that the lines of the function are numbered along theleft hand side of the window. Look at the first line:

function [x,y]= euler_method(f,h,x0,y0,xn).

This line creates a function called euler_method in MATLAB.

The variables in squarebrackets are the outputsof the function. These variables are returned to the commandwindow after the function is called. Thisfunction returns variables called x and y.The variables in round brackets are the inputs of thefunction. Thisfunction has five inputs.What are they?

The % symbol is used to comment out text. This means that whateverappears after a % sign is not executed as part of the code.Explanations are placed after a % symbol. Read the comments that describe how thefunction euler_method.m works.

•For Loops: Line 18 of euler_method.m begins a for loop. This for loop is indexed by the variable i.It is ended on line 21 by the command “end.”The expression “fori=1:n”tells MATLAB to execute the commands inside the for loop for i=1,2,3,. . . all the way up to n.

Note: MATLAB updates the value of the index i with each iteration of the loop, so the command i=i+1need not appear inside the loop.

1)The loop on line 18 is supposed to perform Euler’s method, but lines19 and 20 are incomplete.What shouldbe on these lines?Fix the code, and save your changes.

2)You can tell MATLAB to run the function euler_method from the command window by typing[x,y]=euler_method(f,h,x0,y0,xn),with values or defined variables substituted for the function inputs,f, h, x0, y0, and xn.

In the command window type [x,y]=euler_method(g,h,0,1,1)to solve the initial value problem,dy/dx=g(x,y);y(0)=1, for h=.25, .125, .0625, and .03125. Each time you run euler_method,a plot showing the approximate solution as a function of x will be produced. Edit these plots to includeaxes labels and titles, and insert them here.

3)Describe the solution plots. How does the approximate solution change as h gets smaller?

4)Makea table to show the approximate value of y(1)for each choice of h.  Usethe table to estimate y(1)to within 2 decimal places.  

5)Make a qualitative analysis of this differential equation bydrawing its phase line. What does this analysis suggest will happento the solution, y(x),as x approaches infinity?


IJust need to know how to draw the phaseline on number 5

Answer & Explanation Solved by verified expert
3.8 Ratings (512 Votes)
To Draw the Phase line you have to plot the values of in the xaxis and those of in yaxis Since this is a qualitative analysis you can copy theplot from    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students