Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

Suppose I have the following MATLAB code.

syms a b c1 c2

c1 = a + b + pi*b
c2 = a + b + 0.5*b

Then c1 gets evaluated to a + b + pi*b and c2 to a + (3*b)/2

However, I need MATLAB to calculate double precision values for the coefficients for a and b and not just symbolic numbers.

How do I do this? e.g. I want c1 to be evaluated as a + 4.1416*b and c2 as a+ 1.5*b

Also suppose I am interested in doing arithmetic like c1*c2, c1*5, I would like the coefficients of a and b to evaluated as numbers and not abstract symbolic expressions.

How should I do this?

share|improve this question
    
@ChristianClason - feel free to move your comments to an answer. –  Aron Ahmadia Nov 26 '12 at 22:54
    
@AronAhmadia - done! –  Christian Clason Nov 27 '12 at 11:45
add comment

1 Answer

To evaluate a symbolic expression numerically, you can use subs to insert numerical values for symbolic variables:

>> subs(c1,{a,b},{1.1,1.2})

ans =

    6.0699

(Note that as long as a and/or b are symbolic variables, I don't see a point in evaluating pi or 3/2 numerically. However, vpa seems to do what you want.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.