how to identify certain variables as constants?

For example, I have this equation
A*cos( w0*t+phi) * B*sin(n*w0*t+phi+psi)
where A,B,w0,psi are all constants, and n is a positive non zero integer.
I want to integrate with repsect to psi, from 0 to 2*pi, and I already know the answer is zero.
How do I make the symbolic toolbox understand the problem in a way it can come to that result?

 Accepted Answer

Why not try it?
syms A B w0 t phi psi
syms n positive integer
V = A*cos(w0*t + phi)*B*sin(n*w0*t + phi + psi);
int(V,psi,[0,2*pi])
ans = 
0

3 Comments

thanks for the response John,
whoops, I should have said
"... respect to phi, from 0 to 2*pi, ... "
which results in:
pi*A*B*sin(psi - t*w0 + n*t*w0)
but I know if you work the integration manually, you eventually simplify to a sin()+sin() over a full cycle of 2*pi which is 0. I thought MATLAB was not getting there because of the lack of constraints on the constants. Any ideas?
If I just plug constants in for the variables, I get zero, but I won't alway know the answer ahead of time, to know that is valid.
p.s. and I thought from the manual the way to define n as a positive integer was this syntax:
assume(n, {'positive','integer'})
and what you wrote made two new symbolic variables, named positive and integer
I think you have an old MATLAB release.
clear
syms n positive integer
whos
Name Size Bytes Class Attributes n 1x1 8 sym
No other variables are created. From the help for syms, I see this:
syms ... ASSUMPTION
additionally puts an assumption on the variables created.
The ASSUMPTION can be 'real', 'rational', 'integer', or 'positive'.
Yes, in older releases I could have used assume, but how am I to know what release you are using?
So your real problem is then...
syms A B w0 t phi psi
syms n positive integer
V = A*cos(w0*t + phi)*B*sin(n*w0*t + phi + psi);
int(V,phi,[0,2*pi])
ans = 
πABsin(ψtw0+ntw0)
which MATLAB does not show as zero.
But we can reduce your problem to a simple one. First, A and B are irrelevant, if you expect the answer to be zero.
Consider this variation of your integral...
syms u v phi
int(cos(phi + u)*sin(phi + v),phi,[0,2*pi])
ans = 
πsin(uv)
Thus if we set u=w0*t, v=n*w0*t + psi, we get essentially the same solution, thus
-pi*sin(w0*t - n*w0*t - psi)
And that is zero only under certain circumstances, for specific values of those parameters, when
w0*t - n*w0*t - psi = K*pi
for integer values of K. So unless you have chosen specific values of those parameters, you would not get zero. Or, possibly, you did these computations incorrectly when you did it yourself.

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!