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 个评论
KALYAN ACHARJYA
2020-3-4
Do the calculation again
>> exp(1*(1-sqrt(3)))-1-sin(1*(1-sqrt(3)))-((1*(1-sqrt(3)))^(3))/3
ans =
0.2801
回答(1 个)
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!