off value is returned when plugging into function

I'm starting a project for a class, and I was trying to set up the equations and all. For one case, k=1, c=sqrt(3), and x0=1.
f(x) = e^(k(x-c))
When I would plug in the values into my calculator, I would get F=-0.3755301034 and DF=-1.05499735, but matlab would show the values as F=0.2801 and DF=-0.7988. Is it just something with Matlab or my code?
k = input('k = ');
c = input('c = ');
x0 = input('x0 = ');
err = input('relative error tolerance = ');
f = @(x) exp(k*(x-c))-1-sin(k*(x-c))-((k*(x-c))^(3))/3;
df = @(x) k*exp(k*(x-c))-k*cos(k*(x-c))-k*(k*(x-c))^2;
F = f(1);
DF = df(1);

1 comentario

Do the calculation again
>> exp(1*(1-sqrt(3)))-1-sin(1*(1-sqrt(3)))-((1*(1-sqrt(3)))^(3))/3
ans =
0.2801

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 4 de Mzo. de 2020
Editada: Stephen23 el 4 de Mzo. de 2020
Your calculator calculated sine using degrees, but MATLAB's sin function uses radians.
You will get exactly the same (most likely erroneous) result as your calculator by using sind (input in degrees):
>> k = 1;
>> c = sqrt(3);
>> x = 1;
>> t = k*(x-c);
>> exp(t)-1-sind(t)-(t.^3)/3 % note SIND
ans = -0.37553
Most likely the formula should be interpreted in radians, in which case MATLAB gave you the correct answer and you need to change your calculator for one that can handle radians properly.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 4 de Mzo. de 2020

Editada:

el 4 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by