Error using input Unrecognized function or variable 'x'. Error in untitled (line 2) f1=input('fonksiyonu giriniz: ')

1 Ansicht (letzte 30 Tage)
clc;
fprintf('SECANT METODU\n')
u = input('fonksiyonu girin: ','s');
f = str2func(['@(x)' u]);
x0=input('x0 noktasını giriniz: ');
x1=input('x1 noktasını giriniz: ');
e=input('toleransı giriniz: ');
n=input('iterasyonu giriniz: ');
for i=1:n
x2 = (x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
fprintf('x%d = %.50f/n',i,x2);
if abs(x2-x1)<e
break
end
x0 = x1;
x1 = x2;
end

Antworten (1)

Cris LaPierre
Cris LaPierre am 30 Mai 2022
Bearbeitet: Cris LaPierre am 30 Mai 2022
It may be in part how you are formatting your input equation, but the main problem is that there is no 'lnx' function in MATLAB. You probably mean ln(x), but that is also incorrect. In MATLAB, the natural log is log.
Your input, then, should be log(x)
For , use log10.
  2 Kommentare
Walter Roberson
Walter Roberson am 30 Mai 2022
For future reference:
I looked through a number of different programming languages last year. In nearly all of them that I could find, the natural log was either log() or Log[] . I think I found one lesser-used programming language that used ln() -- it does show up, but in practice it is considerably less common than log

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Exponents and Logarithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by