This is a code written for the bisection method in matlab Wh

This is a code written for the bisection method in matlab. Whenever i ran the program it did not know when to stop. My function was f(x)=-25+82x-90x^2+44x^3-8x^4+.7x^5

I wanted it to approximate 4 iterations (maxit=4) and es=.05 or 5%. which should have gave me 5.26% error. Instead it did 5 iterations giving me 2.7% error. I tried adding in else n>maxit on line 22 which made it worse. I dont know how to fix this issue.

Solution

It is very important to keep an eye on the warning message while working on MATLAB.

A warning message is there in line 1.

\'maxit\' is the parameter in question.

It can be seen that \'maxit\' has not been used in any subsequent lines.

This should give you the solution.

You wanted to do a particular no. of iterations and stop there. But the given code is designed to stop for error only.

That\'s why even for \'maxit\'=4, the code is stopping only when the error is less than the error bound given by you i.e 5%.

A very simple solution to it , if you want to limit the maximum no. of iterations then use

for n=1:maxit    in line 12

this would add an additional stopping condition where maximum no. of iterations are predetermined by you.

I hope this would solve your issue.

This is a code written for the bisection method in matlab. Whenever i ran the program it did not know when to stop. My function was f(x)=-25+82x-90x^2+44x^3-8x^

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site