Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I put the function into MATLAB so I can run it. Using a function Note how the differential equation is hardcoded inside the

image text in transcribed

How do I put the function into MATLAB so I can run it.

Using a function Note how the differential equation is hardcoded inside the for-loop. This is very bad programming practice (can you see why?), but I did it to make things simpler in the demonstration. It is much better practic to define the differential equation inside a function. At the bottom of this file, you will find the definition of a function f. Below I solve the same differential equation again, replacing the explicit formula by a call to the function f. You should do it this way instead. y=zeros(1, N+1); y(1)=1; for n=1:N y(n+1) = y(n) + h* f(t(n),x(n)); end plot(t,y) Your assignment One of the real power of numerical methods is that it allows you to see what the solution looks like, even if you can't solve it exactly. The problem below is an example of a Bernoulli differential equation. These can be solved but require more advanced methods. Question 1: Apply the Euler method to solve dy = 1+1 -(4+1) y 8y dt y(0) = 1 from t = 0 to t = 5. Your code should use a function, just as in the code I used to find z(t) in the most recent section. Modify the above code (using a function f) so that it solves this ODE Note that this problem has exact solution y(t) = 10(t+1) 8 (t + 1) 10 + 9 Using a function Note how the differential equation is hardcoded inside the for-loop. This is very bad programming practice (can you see why?), but I did it to make things simpler in the demonstration. It is much better practic to define the differential equation inside a function. At the bottom of this file, you will find the definition of a function f. Below I solve the same differential equation again, replacing the explicit formula by a call to the function f. You should do it this way instead. y=zeros(1, N+1); y(1)=1; for n=1:N y(n+1) = y(n) + h* f(t(n),x(n)); end plot(t,y) Your assignment One of the real power of numerical methods is that it allows you to see what the solution looks like, even if you can't solve it exactly. The problem below is an example of a Bernoulli differential equation. These can be solved but require more advanced methods. Question 1: Apply the Euler method to solve dy = 1+1 -(4+1) y 8y dt y(0) = 1 from t = 0 to t = 5. Your code should use a function, just as in the code I used to find z(t) in the most recent section. Modify the above code (using a function f) so that it solves this ODE Note that this problem has exact solution y(t) = 10(t+1) 8 (t + 1) 10 + 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions