Question
Using loops in MATLAB Here we will take a simple differential equation of the following form: dy dt = ?3y + 4t 2 We can
Using loops in MATLAB
Here we will take a simple differential equation of the following form: dy dt = ?3y + 4t 2
We can write this equation using loops in the following way: y(n+1) = yn + h(?3yn + 4t 2 n )
Where h is an approximation linear factor and t must increase by, t(n+1) = tn + h Lets assume you want to approximate the values of the differential equation from to to t1.
Then, you can compute the approximation linear factor h as follows: h = t1 ? to N And N the number of steps. The greater the number of time steps, the more accurate the approximation. In this problem you will use a for loop to approximate the corresponding values. Suppress all variables for this problem.
(a) Set up the variables knowing that you will use Eulers approximation to find the values from to = 0 to t1 = 50. You also know that the initial value of y is zero and that the initial value of t must be to. Remember, you must set up the initial values before using the for loop.
(b) Compute the approximation linear factor h knowing that the number of steps is 100.
(c) Set up the for loop using the the second and third equations. Notice that n represents the index and than the for loop must run by N number of steps. (d) Plot y versus t in a first subplot. Title it Approximation with for loop and label the axis. Assume that y represents the position of a particle in meters and that t represents the tim
e in seconds.
(e) You will now compare your approximation with the real solution. The solution to this differential equation is as follows: y = 108 81 t 2 ? 216 243 t + 216 729 ? 8 27 e ?3t Create a symbolic variable t, and plot the above symbolic equation in a second subplot side by side to the next one. Title it Real Solution, include axis labels where y is the position in meters and t is the time in seconds of a particle moving in one dimension. Change the x-axis scale to range from zero to 50. (Hint: look up ezplot() to change the axis).
(f) Provide a comment comparing the real solution and the approximate solutions. Does Eulers approximation method work?
(g) Convert the for loop of Eulers approximation into a while loop. However, in this case, change the upper boundary t1 to 35 and change the number of steps N to 135. Remember that while loops, run as long as the statement is true. 1
(h) In a third subplot, next to the second subplot, plot y versus t of the approximated values computed using the while loop and Eulers approximation method. Title the subplot Approximation with while loop. Add axis labels by knowing that y is the position in meters and t is the time in seconds of a particle moving.
Step 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