필터 지우기
필터 지우기

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.

댓글을 달려면 로그인하십시오.

추가 답변 (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