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!