フィルターのクリア

Solving a Matrix of Independent Equations At the Same Time

1 回表示 (過去 30 日間)
S H
S H 2019 年 1 月 15 日
コメント済み: madhan ravi 2019 年 1 月 15 日
Could you help me fix the syntax of the solve function in the following codes? There should be at least as many answers as the size of the data grid.
syms a b x
[a,b] = ndgrid(-2:2:2,-3:3:3);
equ = x == a.*x - 9.*b.*x.^2 + 128;
answers=solve(equ,x)
It is better to avoid "for loops" to increase the speed. The actual grid data and equations are much more complicated than what I am showing here that cannot be symbilically solved.
It is okay to keep the solutions in a 3 by 3 cell matrix where each cell contains the solutions.
  3 件のコメント
S H
S H 2019 年 1 月 15 日
If the speed of two codes with the same functionality are measured using tic and toc, the code with "for loop" is always slower that the code with vector calculation.
Stephen23
Stephen23 2019 年 1 月 15 日
編集済み: Stephen23 2019 年 1 月 15 日
"If the speed of two codes with the same functionality are measured using tic and toc, the code with "for loop" is always slower that the code with vector calculation."
That is incorrect. If vectorized code requires creating large intermediate arrays it can very easily be much slower that looped code, if it is possible at all. Most probably this also depends on the available memory and the MATLAB version too.

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

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 15 日
syms a b x
equ = x == a.*x - 9.*b.*x.^2 + 128;
answers=solve(equ,x);
[a,b] = ndgrid(-2:2:2,-3:3:3);
Answers=matlabFunction(answers);
Answers(a,b) % final
  6 件のコメント
S H
S H 2019 年 1 月 15 日
Amazing. Thank you.
madhan ravi
madhan ravi 2019 年 1 月 15 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by