Hi all,
I was getting wrong answers for the integeral of the next expression,
>> syms x
>> f(x)=sin(x)+2*cos(x)
f(x) =
2*cos(x) + sin(x)
>> F=int(f(x))
The result integral came as:
F =
-2*cos(x/2)*(cos(x/2) - 2*sin(x/2))
So I tried to operate each term separately to get the right answer, which is different than the first one.
>> F2=int(sin(x))+int(2*cos(x))
F2 =
2*sin(x) - cos(x)
I tried the web version of matlab to check possible bugs within the version I'm using, but I found the same error anyway.
Maybe I am doing it wrong. Please help.

 채택된 답변

Steven Lord
Steven Lord 2021년 3월 10일

0 개 추천

syms x
f=sin(x)+2*cos(x)
f = 
F=int(f)
F = 
F2=int(sin(x))+int(2*cos(x))
F2 = 
You have different results but that doesn't necessarily mean that either is wrong.
simplify(F-F2)
ans = 
The difference between the two solutions is a constant and this is okay due to the constant of integration. But let's check that if we differentiate the results from the three int calls we get back to the original expression.
isAlways(diff(F, x) == f)
ans = logical
1
isAlways(diff(F2, x) == f)
ans = logical
1
Yes in both cases. So you have two different but both correct answers.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 3월 10일

댓글:

2021년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by