Question about numerical integration for cos vs cosd
2 views (last 30 days)
Show older comments
Hi all,
I came across this question yesterday. Here is the code:
syms theta
y = double(int(cos(theta),theta,[0 pi/12]));
The answer, of course, y = 0.2588.
However, when I use cosd instead:
y = double(int(cosd(theta),theta,[0 15]));
Then y = 14.8292.
If I do it by hand the answer is y = 0.2588 for both case.
I'm wondering what happened when we use cosd with int.
I also checked WolframAlpha and it gives me those two different answers as well. Did I misunderstandd anything during my academic years?
0 Comments
Accepted Answer
James Tursa
on 8 Oct 2020
Edited: James Tursa
on 8 Oct 2020
By hand:
int cosd(theta)
= int cos(theta*pi/180)
= sin(theta*pi/180)*180/pi
Integrated from 0 to 15 degrees:
sin(15*pi/180)*180/pi - sin(0*pi/180)*180/pi = 14.8292
Looks like MATLAB got the correct answer to me.
The key is that derivatives and integrals of cosd (and sind etc.) have to account for the rad/deg factor.
I.e., d/dtheta sind(theta) ≠ cosd(theta)
Rather, d/dtheta sind(theta) = cosd(theta) * (pi/180)
To see why this must be so, plot up both cos(x) from 0 to pi/12 and cosd(x) from 0 to 15 on the same plot. Which one has the largest area underneath it? The cosd(x) plot, of course, since it has a lot more x length under it.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!