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!