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)
Radwan Alerqsousi
Radwan Alerqsousi el 11 de Nov. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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
Radwan Alerqsousi
Radwan Alerqsousi el 12 de Nov. de 2020
well, thanks alot the error has gone one more quistion tho
Error: File: aya.m Line: 5 Column: 1
Function definitions are not permitted at the prompt or in scripts.
any clue what is this ?
dpb
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)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by