How to convert symbolic calculation to numeric?

1 回表示 (過去 30 日間)
Amit Kumar
Amit Kumar 2013 年 10 月 22 日
コメント済み: Amit Kumar 2013 年 10 月 22 日
Hi, I want to convert symbolic calculations into numeric one and substitute in the MATLAB program. This is because symbolic computation is taking a lot of time to do. Is there any way to convert symbolic calculation into numeric? Also I have one more question. I defined a function
f=sym('x1^2+2*x2^2+2*x3^2+2*x1*x2+2*x2*x3')
p=[1,1,1];
t2=p(1);
t2=evalAt(f,[x1=p(1),x2=p(2),x(3)=p(3),a=b]);
MATLAB gives error. I really don't understand what is problem. We do such substitutions in other matrices a=p(1) and so on. Why is this error? Really hard time for me. People, please help.

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 22 日
Where did you do the
syms x1 x2 x(3) a
Also note that your expression uses x3 but your evalAt uses x(3)
  4 件のコメント
Walter Roberson
Walter Roberson 2013 年 10 月 22 日
evalAt is a MuPAD function that has no direct MATLAB interface. If you want to use it you will need to use feval() or evalin()
t2 = feval('evalAt', f, {x1=p(1),x2=p(2),x3=p(3),a=b});
For your other question, look at matlabFunction()
Amit Kumar
Amit Kumar 2013 年 10 月 22 日
A Jenkins: My mistake, I did define b but forgot to put in this code. Thanks for this!
Walter Roberson: Thank you very much providing some solution. I was trying really hard to get this. Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeUtilities for the Solver についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by