MATH 2370 Lecture Notes - Lecture 9: Matlab, Bisection Method

14 views3 pages

Document Summary

Note: in such cases, we may be able to write the algorithm recursively to compute the function because the function is defined in terms of itself. => we have what is called a recursive function. Iterative way: function y=fac(n) y=n; for i=n-1:-1:1 y=y*i end end. Note: as with a loop, we have to stop it, to avoid infinite recursion => we need a base case - a condition (often some if, or if-else, etc. ) on which to stop recursion. => function y=fac(n) y=n; if y>1 %can also put y>=2, also checks for base case y=y*fac(n=1) end. Intro to programming with matlab page 1 end end. Variation: function y=fac(n) if n>1 y=n*fac(n=1) else y=1. In some applications, a sequence may be defined recursively ex: a sequence is an ordered list of numbers ( ) (initial condition) function a=recseq(n) %a is a vector with etc. a=zeros(n,1) if n==1.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related textbook solutions

Related Documents

Related Questions