Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
symbolic expression

Subject: symbolic expression

From: Dimitar Dimitrov

Date: 17 Nov, 2007 10:37:54

Message: 1 of 7

Hello,

When I am using the symbolic toolbox,
and for example I do matrix multiplication, the numerical
coefficients are represented as a ratio like that:

7278064770679435/9007199254740992*cos(a)

where "a" is defined as "syms a"

So my question is how do I simplify this to

0.80802750831215*cos(a)

I tried using "simple", "simplify", "subs", but ...

Thank you,
Dimitar

Subject: symbolic expression

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 17 Nov, 2007 17:16:20

Message: 2 of 7

In article <fhmga2$ded$1@fred.mathworks.com>,
Dimitar Dimitrov <mail_mitko@mathworks.com> wrote:

>When I am using the symbolic toolbox,
>and for example I do matrix multiplication, the numerical
>coefficients are represented as a ratio like that:

>7278064770679435/9007199254740992*cos(a)

>where "a" is defined as "syms a"

>So my question is how do I simplify this to

>0.80802750831215*cos(a)

>I tried using "simple", "simplify", "subs", but ...

Possibly evalf().


However, what you are asking to do is not simplifying the formula.
0.80802750831215 = 16160550166243/20000000000000
not 7278064770679435/9007199254740992 so you are only -approximating-
the formula.

If your intent is to convert it to Matlab's double precision
then you have missed a digit:

>> 7278064770679435/9007199254740992

ans =

       0.808027508312152

>> 7278064770679435/9007199254740992 - 0.80802750831215

ans =

      1.88737914186277e-15

>> eps

ans =

      2.22044604925031e-16


--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

Subject: symbolic expression

From: Dimitar Dimitrov

Date: 17 Nov, 2007 18:24:39

Message: 3 of 7

Thank you for the reply.

Thats right I want to "approximate"

7278064770679435/9007199254740992 with a double precision,
or number or, scientific format.

Any suggestions are welcome.


Cheers,
Dimitar


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fhn7l4$c3b$1@canopus.cc.umanitoba.ca>...
> In article <fhmga2$ded$1@fred.mathworks.com>,
> Dimitar Dimitrov <mail_mitko@mathworks.com> wrote:
>
> >When I am using the symbolic toolbox,
> >and for example I do matrix multiplication, the numerical
> >coefficients are represented as a ratio like that:
>
> >7278064770679435/9007199254740992*cos(a)
>
> >where "a" is defined as "syms a"
>
> >So my question is how do I simplify this to
>
> >0.80802750831215*cos(a)
>
> >I tried using "simple", "simplify", "subs", but ...
>
> Possibly evalf().
>
>
> However, what you are asking to do is not simplifying the
formula.
> 0.80802750831215 = 16160550166243/20000000000000
> not 7278064770679435/9007199254740992 so you are only
-approximating-
> the formula.
>
> If your intent is to convert it to Matlab's double precision
> then you have missed a digit:
>
> >> 7278064770679435/9007199254740992
>
> ans =
>
> 0.808027508312152
>
> >> 7278064770679435/9007199254740992 - 0.80802750831215
>
> ans =
>
> 1.88737914186277e-15
>
> >> eps
>
> ans =
>
> 2.22044604925031e-16
>
>
> --
> "Okay, buzzwords only. Two syllables, tops." -- Laurie
Anderson

Subject: symbolic expression

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 17 Nov, 2007 19:11:14

Message: 4 of 7

In article <fhnbl7$4be$1@fred.mathworks.com>,
Dimitar Dimitrov <mail_mitko@mathworks.com> wrote:

>Thats right I want to "approximate"

>7278064770679435/9007199254740992 with a double precision,
>or number or, scientific format.

>Any suggestions are welcome.

Did the evalf() I suggested already not work? I have not been
able to locate a description of the functions in the symbolic toolbox,
but I find enough postings to suggest that it is evalf() is present.
--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

Subject: symbolic expression

From: Dimitar Dimitrov

Date: 17 Nov, 2007 20:40:32

Message: 5 of 7

Yes it works!

maple('evalf',z),
where z = 7278064770679435/9007199254740992*cos(a)

and the result is:
.80802750831215186533285077530309*cos(a)

precisely what I expect.

I am sorry for my previous post.
Actually, I typed doc evalf, but there was nothing in the
help, so I thought that I simply dont have this function.
But after your second post I decided to check again, and I
found out that I have to call it with "maple".


Thank you very much!
Dimitar

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fhneci$jqe$1@canopus.cc.umanitoba.ca>...
> In article <fhnbl7$4be$1@fred.mathworks.com>,
> Dimitar Dimitrov <mail_mitko@mathworks.com> wrote:
>
> >Thats right I want to "approximate"
>
> >7278064770679435/9007199254740992 with a double precision,
> >or number or, scientific format.
>
> >Any suggestions are welcome.
>
> Did the evalf() I suggested already not work? I have not been
> able to locate a description of the functions in the
symbolic toolbox,
> but I find enough postings to suggest that it is evalf()
is present.
> --
> "Okay, buzzwords only. Two syllables, tops." -- Laurie
Anderson

Subject: symbolic expression

From: Nasser Abbasi

Date: 18 Nov, 2007 02:24:16

Message: 6 of 7


"Dimitar Dimitrov" <mail_mitko@mathworks.com> wrote in message
news:fhnbl7$4be$1@fred.mathworks.com...
> Thank you for the reply.
>
> Thats right I want to "approximate"
>
> 7278064770679435/9007199254740992 with a double precision,
> or number or, scientific format.
>
> Any suggestions are welcome.
>
>
> Cheers,
> Dimitar
>

In addition to evalf() You can also try vpa()

EDU>> help vpa
 VPA Variable precision arithmetic.
    R = VPA(S) numerically evaluates each element of the double matrix
    S using variable precision floating point arithmetic with D decimal
    digit accuracy, where D is the current setting of DIGITS.
    The resulting R is a SYM.

EDU>> s=7278064770679435/9007199254740992 ;
EDU>> vpa(s)

ans =

.80802750831215186533285077530309

Nasser

Subject: symbolic expression

From: Dimitar Dimitrov

Date: 18 Nov, 2007 09:43:12

Message: 7 of 7

Thank you for the reply!
This seems to be another good way to do it (a bit slower
than using directly maple('evalf',z); though).

Dimitar

"Nasser Abbasi" <nma@12000.org> wrote in message
<pnN%i.19879$4k.16045@newsfe11.phx>...
>
> "Dimitar Dimitrov" <mail_mitko@mathworks.com> wrote in
message
> news:fhnbl7$4be$1@fred.mathworks.com...
> > Thank you for the reply.
> >
> > Thats right I want to "approximate"
> >
> > 7278064770679435/9007199254740992 with a double precision,
> > or number or, scientific format.
> >
> > Any suggestions are welcome.
> >
> >
> > Cheers,
> > Dimitar
> >
>
> In addition to evalf() You can also try vpa()
>
> EDU>> help vpa
> VPA Variable precision arithmetic.
> R = VPA(S) numerically evaluates each element of the
double matrix
> S using variable precision floating point arithmetic
with D decimal
> digit accuracy, where D is the current setting of DIGITS.
> The resulting R is a SYM.
>
> EDU>> s=7278064770679435/9007199254740992 ;
> EDU>> vpa(s)
>
> ans =
>
> .80802750831215186533285077530309
>
> Nasser
>
>

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us