MATLAB符號表示式 函式 求值

2021-07-23 12:17:13 字數 943 閱讀 5206

有時候需要解符號表示式得到某個量關於其他量的顯式表示式,matlab解出的結果任然是符號表示式,我們希望可以用這個表示式建構函式,進一步求值。

function test

syms x y

y=solve(' x^2+y^2+x*y-y*log(x)=0','y');

class(y)

y(1)

f=cell(1,length(1));

for i=1:length(y)

f=eval(['@(x)',vectorize(y(i))]);

endclassf=class(f)

f(rand(5))

end

the result  as follow:

classf =

function_handle

ans =

-0.5121 + 0.6097i  -0.0088 + 0.0000i  -0.5144 + 0.5851i  -0.5286 + 0.4570i  -0.2353 + 0.0000i

-0.0040 + 0.0000i  -0.5240 + 0.4956i  -0.5252 + 0.4852i  -0.0218 + 0.0000i  -0.5024 + 0.7524i

-0.0440 + 0.0000i  -0.0049 + 0.0000i  -0.5025 + 0.7512i  -0.0003 + 0.0000i  -0.5522 + 0.2589i

-0.0837 + 0.0000i  -0.5394 + 0.3694i  -0.5032 + 0.7352i  -0.5198 + 0.5324i  -0.5497 + 0.2816i

-0.5329 + 0.4220i  -0.2601 + 0.0000i  -0.0829 + 0.0000i  -0.2712 + 0.0000i  -0.5055 + 0.6951i

表示式求值

程式的說明見清華大學出版社 資料結構 c語言版 include include define stack init size 40 define stackincrement 20 define ok 1 define false 0 typedef structs stack typedef st...

表示式求值

既然是表示式求值,自然需要在記憶體中儲存計算結果以及中間值。在 用c語言寫直譯器 一 中提過 變數要求是若型別,而 c 語言中的 view plaincopy to clipboardprint?in basic io.h define memery size 26 typedef enum var...

表示式求值

寫了乙個下午,各種糾結,各種問,終於搞明白了。但是自己還是想出來的一點東西的。很爽歪歪的,哈哈。先貼第一次的 include include include include include includeusing namespace std char data 7 7 int sign char ...