Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: symbolic variables + symbolic numerical manipulations?
Replies: 7   Last Post: Jun 14, 2013 4:23 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Alan Weiss

Posts: 1,267
Registered: 11/27/08
Re: symbolic variables + symbolic numerical manipulations?
Posted: Jun 12, 2013 8:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 6/12/2013 4:44 AM, Uwe Brauer wrote:
> Hello
>
> I thought that when using symbolic variables, Matlab treats numbers,
> which are multiplied by this variables also in a "symbolic" way.
>
> Look at the following.
>
> A=[1/4, 1/4 - sqrt(3)/6;1/4 + sqrt(3)/6, 1/4 ]
> b=[1/2, 1/2]
>
>
> I=eye(2);
> e=ones(2,1);
> r= 1 + z*b*inv((I-z*A))*e;
>
> Now when doing the calculations by hand r should be:
> r= (1 + 0.5*z + 1/12*z.^2)./(1 - 0.5*z + 1/12*z.^2);
>
> Matlab gives me:
> (20282409603651670423947251286016
> +10141204801825835211973625643008*z +
> 1690200800304305672809963274929*z^2)/
> (20282409603651670423947251286016 -
> 10141204801825835211973625643008*z
> +1690200800304305672809963274929*z^2)
>
> So it seems that Matlab did the calculations with finite arithmetic in
> digital representation and later converts the result to fractions.
>
> There is no way that Matlab would do the calculations from the starts
> in fractions doing "symbolic" manipulations with numbers?
>
> thanks
>
> Uwe Brauer


It depends on how you make A. You probably did something like

A=sym([1/4, 1/4 - sqrt(3)/6;1/4 + sqrt(3)/6, 1/4 ]);

which gives

A =

[ 1/4, -174177321749703/4503599627370496]
[ 2425977135434951/4503599627370496, 1/4]

Instead, you should execute

A = sym('[1/4,1/4 - sqrt(3)/6;1/4 + sqrt(3)/6, 1/4]');

which gives

A =

[ 1/4, 1/4 - 3^(1/2)/6]
[ 3^(1/2)/6 + 1/4, 1/4]

Then if you follow through with the rest of your calculations you get

r =

(z^2*(2*3^(1/2) + 3))/(2*(z^2 - 6*z + 12)) - (z^2*(2*3^(1/2) -
3))/(2*(z^2 - 6*z + 12)) - (3*z*(z - 4))/(z^2 - 6*z + 12) + 1

as you wanted.

Alan Weiss
MATLAB mathematical toolbox documentation



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.