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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -