MuPAD generate::MATLAB to include element by element (dot) vector operations

1 回表示 (過去 30 日間)
Kiron
Kiron 2011 年 12 月 3 日
Hello,
I am trying to compute a complicated analytical expression in MuPAD and generate code to implement in a MATLAB function, however I can't get the generated code to support the dot-syntax MATLAB requires for element by element vector operations. Here is a simplified example of what I am trying to do.
In MuPAD>>
f:=(c*z^3)/(a*x^2+b*y^2): print(Unquoted,generate::MATLAB(generate::optimize(f)))
Returns>>
t18 = z^2;
t17 = (c*t18*z)/(a*x^2+b*y^2); (c*z^3)/(a*x^2 + b*y^2)
My ideal output would be:
t18 = z.^2;
t17 = (c.*t18.*z)./(a.*x.^2+b.*y.^2);
There doesn't seem to be an option to select this in MuPAD's generate() help.
Anyone have experience with this?
Thanks,
Kiron

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 12 月 3 日
The output is a text string. You can run MATLAB's vectorize() on the string lines.
  1 件のコメント
Kiron
Kiron 2011 年 12 月 3 日
Thanks for the quick reply!
I did not know about the vectorize() function, that will be useful at some point.
The extra function generate::optimize() can create something like 50 lines of code, but greatly simplifies and speeds up code. Wouldn't I have to run vectorize() on each line of code for that to work?
Right now, I simply find and replaced every '*', '/', and '^' to '.*', './' and '.^'. Crude, but effective.
-KM

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

カテゴリ

Help Center および File ExchangeGet Started with MuPAD についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by