Question: 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

 How do I put the function into MATLAB so I can

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!