Question

In: Advanced Math

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

Euler’s Method and Introduction to MATLAB

Start MATLAB

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

>> 2+2

If you want to suppress the output of a command follow it with ;.  For example >>2+2;

Practice evaluating a few expressions in the command window. (In MATLAB multiplication is represented by * so 3*2=6).

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

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

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

Now that you have created the function g(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 compute g(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.m you will see that the lines of the function are numbered along the left 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 square brackets are the outputs of the function. These variables are returned to the command window after the function is called. This function returns variables called x and y. The variables in round brackets are the inputs of the function. This function has five inputs. What are they?

The % symbol is used to comment out text. This means that whatever appears after a % sign is not executed as part of the code. Explanations are placed after a % symbol. Read the comments that describe how the function 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 for i=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+1 need not appear inside the loop.

1) The loop on line 18 is supposed to perform Euler’s method, but lines 19 and 20 are incomplete. What should be 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 include axes labels and titles, and insert them here.

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

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

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


I Just need to know how to draw the phaseline on number 5

Solutions

Expert Solution

To Draw the Phase line, you have to plot the values of in the x-axis and those of in y-axis. Since this is a qualitative analysis, you can copy the plot from MATLAB and draw it by hand.

Now, the places where make an arrow in the x-axis pointing towards the positive direction.
And, the places where make an arrow in the x-axis pointing towards the negative direction
The places where , make a circle. These are the stationary points of the Differential Equation

If there is a stationary point on your phase line which has arrows from both sides going into it, then it is a stable fixed point and at the value of will stabilize at that value, otherwise the stationary point is unstable and the value of will go to either depending on the direction of the arrows and the initial condition.


Related Solutions

Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you cannot give correct MATLAB
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has...
how can I change the Gauss-Seidel method to SOR method code in Matlab? The question has shows that In implementing SOR method in MATLAB, one should not calculate Tw and cw by formulas Tw = (D -wL)^(-1)[(1-w)D+wU)] and Cw = w(D-wL)^(-1)b , where w stands for omega and using MATLAB's built-in inv function, since this function requires O(n^3) flops and therefore the whole matter loses its point. I have tried for many times but I can't get the correct answers....
Download everything.c. You can compile and run it with the usual commands. You know that putting...
Download everything.c. You can compile and run it with the usual commands. You know that putting all your code into a single file is bad form. Therefore, your goal is to refactor everything.c so that the code is in multiple source (.c and .h) files, as well as write a Makefile to compile and run the program. Here are your constraints: There should be no code duplication Each .c and .h file must only #include header files that it actually...
Working with MATLAB arrays. You can check your answers on MATLAB but do not include a...
Working with MATLAB arrays. You can check your answers on MATLAB but do not include a script file or MATLAB output for this problem . Just write the commands you would use each part. You may not 'hard code' which means you cannot just write in the answers. Show the MATLAB commands You have the following array: Data1[ 3.6 8.9 2.5 4.6 12.0 3.3 7.8 1.5] A) Write the command(s) you would use to order the values in the array...
Use matlab code for bisection method and regula falsi. Thank you!
Use matlab code for bisection method and regula falsi. Thank you!
Two introduction paragraphs to start an essay on how small businesses can survive the COVID-19 pandemic?...
Two introduction paragraphs to start an essay on how small businesses can survive the COVID-19 pandemic? Including these subtitles in the second paragraph: The Covid-19 pandemic and government response, The effect of the pandemic on small businesses, the challenges small business owners would face, and lastly, can small businesses survive the Covid-19 pandemic?
You are required to revise function shell_execute() in simple-execute.c, so the program can execute commands with...
You are required to revise function shell_execute() in simple-execute.c, so the program can execute commands with up to two pipes. Basically, your program should be able to handle the case in which there is at least one space before or after “|” such as: $$$ ls -l | grep D | wc -l $$$ ls -l | grep D If there is no space between or after “|”, for example, for the following case: $$$ ls| “ls|” is treated as...
If you are about to start a Power Plant construction which type of layout would you...
If you are about to start a Power Plant construction which type of layout would you apply in your production. Justify your opinion.
Can you provide a sample programming for 2D plane frame in MATLAB ?
Can you provide a sample programming for 2D plane frame in MATLAB ?
Binomial Hypothesis Test. While this method is limited in the type of data it can handle...
Binomial Hypothesis Test. While this method is limited in the type of data it can handle (binary - "success/failure" outcomes), it is powerful in providing figures of authority with scientific information off of which to base important decisions. There is a limitation to using this method and, statistically, this notion refers to the "power" of a test. First, let's suppose that you are a disease outbreak coordinator for the Center for Disease Control and Prevention. A recent flu outbreak has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT