Use the bisection method to find solutions in Matlab? -


i trying solve following question:

use bisection method find solutions accurate within 10^−4 on interval [−5, 5] of following functions:

f(x)= x^5-10x^3-4 

this code:

function sol=bisect(fn,a,b,tol)  %bisection method nonlinear function fa=feval(fn,a);fb=feval(fn,b); if fa*fb>0;fprintf('endpoints have same sign')    return end k=0; while abs (b - a)>tol    c =(a+b)/2;    fc=feval(fn,c);    if fa*fc < 0; b=c; else = c;         k=k+1;    end end sol=(a+b)/2; 

when run program, do:

a= -5 b=5 fn =  x^5-10x^3-4 

but last line returns error:

undefined function or variable x

to define equation can evaluated feval, need define function.

try defining fn fn=@(x)(x^5-10x^3-4). way can use feval(fn,3).


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -