Problem with integrating Sin to Cos

7 Ansichten (letzte 30 Tage)
Ruwan Badenhorst
Ruwan Badenhorst am 3 Apr. 2021
Beantwortet: Paul am 4 Apr. 2021
Good day.
I am trying to integrate the following equation but Matlab seems to not integrate Sin to Cos?
Not sure if the error is in my code.
ode = (2/pi) * (int(sin(n*x), 0, pi/2))
ode = (4*sin((n*pi)/4)^2)/(n*pi)
Any help will be appreciated.
Thank you
  2 Kommentare
Jan
Jan am 3 Apr. 2021
Do you get an error message? Then please share it,
Ruwan Badenhorst
Ruwan Badenhorst am 4 Apr. 2021
Hi Jan. No error message.
The issue I'm having is that sin will not integrate to cos with the limits "0" and "pi/2"
The answer still shows it is sin, but sin integrated is -cos

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Apr. 2021
syms n x
Pi = sym(pi);
ode = (2/Pi) * (int(sin(n*x), x))
ode = 
result1 = simplify(subs(ode,x,Pi/2) - subs(ode,x,0))
result1 = 
result2 = (2/Pi) * (int(sin(n*x), x, 0, Pi/2))
result2 = 
result1 - result2
ans = 
simplify(ans)
ans = 
0
The result you are seeing is not wrong: it is the same result, expressed differently due to an identity.
  1 Kommentar
Ruwan Badenhorst
Ruwan Badenhorst am 4 Apr. 2021
Thank you very much Walter. You deserve a Bells!
I see where I made my error.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Paul
Paul am 4 Apr. 2021
If you just want ode in terms of cos()
>> ode = int(sin(n*x),x,0,pi/2)
ode =
(2*sin((pi*n)/4)^2)/n
>> rewrite(ode,'cos')
ans =
-(2*(cos((pi*n)/4)^2 - 1))/n
The "by hand" solutions is:
>> sol=1/n*(-cos(n*pi/2) + cos(0*n))
sol =
-(cos((pi*n)/2) - 1)/n
Show the two solutions are equal:
>> simplify(ode-sol)
ans =
0
Wrangling ode into the form of sol takes a few steps. Perhaps someone else can do it easier:
>> simplify(combine(rewrite(ode,'cos')))
ans =
-(cos((pi*n)/2) - 1)/n

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by