I want to write a matlab script that finds solutions of function f(x) = e^x – 3x. I tried to write some code. My matlab code should include iteration table and graphic of function. Can anyone help me please with a code or give me advices?
f=@(x) exp(x) - 3*x ; a = 0; b = 1;tol = 1e-8; if (f(a)*f(b) > 0) error ('invalid choice of interval') end r=0; n=0; while ((b-a)/2 > 0) n = n + 1; r = (a+b)/2; if (f(r) == 0) break; elseif (f(a)*f(r) <= 0) b = r ; else a = r; end end
Best Answer