Salve a tutti, ho un errore (penso banale) che mi esce quando provo ad eseguire questo programmino in matlab:
function [zero,niter] = bisezione (a,b,fun,toll,num_iterazioni)
x=[a, (a+b)*0.5, b];
fx=eval(fun);
niter=0;
i= (b-a)*0.5;
while i >= toll & niter <= num_iterazioni
niter=niter+1;
if sign(fx(1))*sign(fx(2)) < 0
x(3) = x(2);
x(2) = x(1)+(x(3)-x(1))*0.5;
fx=eval(fun);
i=(x(3)-x(1))*0.5;
elseif sign(fx(2))*sign(fx(3)) < 0
x(1) = x(2);
x(2) = x(1)+(x(3)-x(1))*0.5;
fx=eval(fun);
i=(x(3)-x(1))*0.5;
else
x(2)=x(find(fx==0)); i=0; end
end;
zero=x(2);
Il problema è nella parte in grassetto.
Mi dice:
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> bisezione at 4
fx=eval(fun);
qualcuno sa il motivo?
ho fatto varie prove sostituendo la variabile fx con un array di 3 elementi come dovrebbe essere ma niente da fare.![]()

Rispondi quotando