Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Coding must be done in MATLab 4) (13 pts) Forward/Backward Euler a(3) Write a general-purpose Forward Euler function (it should take a function handle for

Coding must be done in MATLab

4) (13 pts) Forward/Backward Euler

a(3) Write a general-purpose Forward Euler function (it should take a function handle for calculating the derivative, initial x value, final x value, initial y value, and step size as inputs). Assume that dy/dx is only a function of y.

b(3) Write a general-purpose Backward Euler function (it should take the same inputs as above, but use root finding to solve the implicit equation you may use the Secant code that I've posted on KSOL to perform this). Note: you can call functions from within functions, and you can absolutely create a function handle that uses another function handle. For the next two problems (c&d), use the following: dy/dx = (-7)y; y0 = 10, over the interval [0,1].

c(3) Investigate the stability we discussed in class by choosing different h values you have freedom here. Find at least three different types of behavior for the Forward Euler method, and plot them.

d(2) Plot the same step sizes with Backward Euler. Compare the behavior (using words).

e(2) Compare the computation time (using numbers and words).

Bisection.m code

%%-------------------Bisect.m--------------------------------------

function [bisect]= Bisect(xl,xu,es,imax,xr,iter,ea) iter=0;

while ( (ea > es) | (iter<=imax)) xrold=xr; xr=(xl-xu)/2; iter=iter+1; if(xr~= 0) ea=abs((xr-xrold)/xr) *100; end test=f(xl)*f(xr); if (text>0) xl=xr; else ea=0; end end bisect=xr;

%----------------------------------------------------------------------------------

%%-------------------------f.m---------file to define your function--------------------------

function f=f(x) f= x^10 - 10*x^5 +0.4*x - 0.4;

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_2

Step: 3

blur-text-image_3

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago