How can i modify the matlab built-in function?

조회 수: 9 (최근 30일)
Aleem Ayobami
Aleem Ayobami 2021년 7월 12일
댓글: Walter Roberson 2021년 7월 19일
supppose i defined a matrix A
how can i modify the inv(A)
  댓글 수: 1
dpb
dpb 2021년 7월 12일
Just write your own version and put it in the MATLABPATH before the builtin one.
I DO NOT recommend you do this, however; doing that will not only give you the modified version but may cause other builtin functions that may use inv to use it instead as well and depending upon what modifications are made, either case code to error, run but produce incorrect results, or perhaps run with correct results.
If you have a special case routine that you do need for some purpose, name it uniquely and use it instead, don't mung on built ins -- and particularly numerical routines buried in the bowels of MATLAB.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 12일
Here is the code for inverse. You can modify it as you see fit.
regexprep(char(evalin(symengine, 'expose(symobj::inv)')),'\\n',newline)
ans =
'proc(A) : Type::MATLABOutput name symobj::inv; local result, N; begin A := symobj::tomatrix(A); if (N := A::dom::matdim(A)[1]) <> A::dom::matdim(A)[2] then error(message(\"symbolic:sym:InputMustBeSquare\")) end_if; result := 1/A; if result = FAIL then result := matrix(N, N, infinity) end_if; symobj::standardForm(result) end_proc'
  댓글 수: 2
Aleem Ayobami
Aleem Ayobami 2021년 7월 19일
Thank you Sir, but i need more information and answers on how to modify the code above.
Walter Roberson
Walter Roberson 2021년 7월 19일
Example:
oldsource = char(evalin(symengine, 'expose(symobj::inv)'));
newsource = 'proc(A) : Type::MATLABOutput name symobj::inv; begin error("Never gonna give you up"); end_proc'
newsource = 'proc(A) : Type::MATLABOutput name symobj::inv; begin error("Never gonna give you up"); end_proc'
feval(symengine, 'unprotect', 'symobj')
ans = 
ProtectLevelError
feval(symengine, '_assign', 'symobj::inv', newsource)
ans = 
proc symobj::inv(A) ... end
After which
inv(sym(ones(2,3)))
Error using sym/inv (line 22)
Error in MuPAD command: Never gonna give you up [symobj::inv].
You can see that inv() operating on symbolic objects has been replaced with new source code.

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

추가 답변 (0개)

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by