Solving a Matrix of Independent Equations At the Same Time

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by