Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

There are a way of instruct the matlab to use sin(pi) = 0 in the symbolic computations?

784 views
Skip to first unread message

Fernando

unread,
Jan 28, 2013, 9:55:08 AM1/28/13
to
Hi,

I have the equations system eqs = [(sin(2*q1)*i)/2; -(sin(2*q1)*i)/2] and when I do solve(eqs == 0) I get zero as unique solution, I know that, due to limited precision, is correct the matlab does not to make sin(pi) = 0. But, would be very usefull to me if I could make some symbolic computations using sin(pi) = 0, and equally cos(pi/2) = 0. There are a way of instruct the matlab to use both sin(pi) and cos(pi/2) equal to zero in the symbolic computations?


This would greatly simplify my life! :)

Best regards!

Steven_Lord

unread,
Jan 28, 2013, 11:04:03 AM1/28/13
to


"Fernando " <ferna...@gmail.com> wrote in message
news:ke63gc$c5r$1...@newscl01ah.mathworks.com...
> Hi,
>
> I have the equations system eqs = [(sin(2*q1)*i)/2; -(sin(2*q1)*i)/2]
> and when I do solve(eqs == 0) I get zero as unique solution, I know that,
> due to limited precision, is correct the matlab does not to make sin(pi) =
> 0. But, would be very usefull to me if I could make some symbolic
> computations using sin(pi) = 0, and equally cos(pi/2) = 0. There are a way
> of instruct the matlab to use both sin(pi) and cos(pi/2) equal to zero in
> the symbolic computations?

Make it symbolic.

spi = sym(pi);
sin(spi)
cos(spi/2)

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Fernando

unread,
Jan 28, 2013, 11:48:08 AM1/28/13
to
> Make it symbolic.
>
> spi = sym(pi);
> sin(spi)
> cos(spi/2)
>
> --
> Steve Lord
> sl...@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Hi Steve, thanks by your attention.

I think that I can't do it. My equations system is:

sin(2*q1)*i)/2 == 0
-(sin(2*q1)*i)/2 == 0

Then, pi is not in my equation, it must be "tested" as solution internally by Matlab, however, the matlab does not recognize pi as solution. I think that I need a way of instruct the matlab to internally use sin(pi) = 0 in the symbolic computations when solve the equations system.


Best ragards!

Christopher Creutzig

unread,
Feb 28, 2013, 7:36:52 AM2/28/13
to
On 28.01.13 17:48, Fernando wrote:

> I think that I can't do it. My equations system is:
>
> sin(2*q1)*i)/2 == 0
> -(sin(2*q1)*i)/2 == 0
>
> Then, pi is not in my equation, it must be "tested" as solution internally by Matlab, however, the matlab does not recognize pi as solution. I think that I need a way of instruct the matlab to internally use sin(pi) = 0 in the symbolic computations when solve the equations system.

Internally, it does find this solution along with all the other
infinitely many ones, as you can see, e.g., by using the MuPAD Notebook
Interface or by calling the MuPAD solve function via feval:

>> syms q1
>> pretty(feval(symengine, 'solve', sin(q1)==0))

+- -+ { +- -+ | }
| q1 | in { | pi k | | k in Z_ }
+- -+ { +- -+ | }
>> pretty(feval(symengine, 'solve', sin(q1)==0, q1))

{pi k | k in Z_}

Now, such an infinite solution set is not easy to use in MATLAB code.
For that reason, the MATLAB command SOLVE generally tries to extract a
(hopefully representative) finite subset of solutions for the input. If
you have special requirements on this set, it may be worth trying to
tell the system something about your variables:

>> assume(q1 > 0)
>> solve(sin(q1)==0)

ans =

2*pi

or even

>> assume(q1 > 0), assumeAlso(q1 < 4)
>> solve(sin(q1)==0)

ans =

pi


Note that the MATLAB function SOLVE does a few additional things on your
input, too, so there is no easy drop-in replacement that directly calls
the MuPAD command, even if your code can handle the output. But if you
think that getting the complete solution set is something the Symbolic
Math Toolbox should really offer, by all means let MathWorks' tech
support know.


HTH,
Christopher

Fernando

unread,
Mar 1, 2013, 6:52:07 AM3/1/13
to
Christopher,


Great answer! Thank you very much by your precious help! :)


Best regards!

Christopher Creutzig <Christophe...@mathworks.com> wrote in message <512F4F64...@mathworks.com>...

Fernando

unread,
Jun 29, 2013, 5:40:10 PM6/29/13
to
I'm with problem about this again! :(

See, http://www.mathworks.com/matlabcentral/newsreader/view_thread/330310!

I already try some ways using mupad, but nothing, not work!
0 new messages