Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
dont know what is that error in the last three lines
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
f=@ () cos(x) +1/(1+x^2 ); %%Given function f(x)
fd=@(x) -sin(x)-2*x/(1+x^2); %%Derivative of the function f'(x)
root=Newton cap Raphson(f,fd,1.5,0.05,1 10); %Function call to compute the root of the function with guess 1.5 and specified error and tolerance
function Xs = NewtonRaphson(Fun, under, Xo ,Err,imax) %%Function which implements Newton Raphson Method
disp('Values in each iteration:' )
for(i = 1:max) %%Runs a loop from 1 to maximum iterations
Xi=Xo -Fun(Xo )/Funder(Xo ) ; %%NR method updating scheme
disp(Xi) %Display current root
if (abs((Xi-Xo)/Xo)<Err) %%lf error is less break
Xs = Xi ;
break
end
Xo=Xi; %%Update
end
if(i==imax) %%lf maximum iteration reached
fprintf('Solution not obtained in %i iterations',imax)
Xs=( 'No Answer' );
end
end
??? root=Newton cap Raphson(f,fd,1.5,0.05,1 10); %Function call to compute the root of the function with guess 1.5 and specified error and tolerance
|
Error: Unexpected MATLAB expression.
4 comentarios
dpb
el 12 de Nov. de 2020
Exactly what is says it is -- you can't define a function at the command line or (prior to a pretty recent release altho I don't recall which one) in a script m-file.
Functions can only be defined in an m-file of the same name in that case. So your function would be saved in a disk file named NewtonRaphson.m
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!