How can i modify the matlab built-in function?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aleem Ayobami
am 12 Jul. 2021
Kommentiert: Walter Roberson
am 19 Jul. 2021
supppose i defined a matrix A
how can i modify the inv(A)
1 Kommentar
dpb
am 12 Jul. 2021
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.
Akzeptierte Antwort
Walter Roberson
am 12 Jul. 2021
Here is the code for inverse. You can modify it as you see fit.
regexprep(char(evalin(symengine, 'expose(symobj::inv)')),'\\n',newline)
2 Kommentare
Walter Roberson
am 19 Jul. 2021
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'
feval(symengine, 'unprotect', 'symobj')
feval(symengine, '_assign', 'symobj::inv', newsource)
After which
inv(sym(ones(2,3)))
You can see that inv() operating on symbolic objects has been replaced with new source code.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!