How to solve 'Error using symengine. Invalid input. 'expression' is expected.'?

15 ビュー (過去 30 日間)
Vuong Hoang
Vuong Hoang 2018 年 4 月 20 日
コメント済み: Walter Roberson 2018 年 4 月 21 日
Variables that have been defined: Ta(array),Tc(array), alpha(number), gammar(array). Undefined variables: Tz(sym). I wanna solve for Tz
syms Tz mcphayphayvz
mcv=19.806+(0.00419/2).*Ta
mcphayphayvz=19.806+(0.00419/2).*Tz+0.5.*Tz.*((360.34+252.4*alpha)^(10^-5))
mcphayvc=(mcv+gammar.*mcphayphayvz)./(1+gammar)
Tz=solve('Tz=(((xiz*(QH-deltaQH))./(M1.*(1+gammar)))+mcphayvc.*Tc)./(betaz.*mcphayphayvz)',Tz)

採用された回答

Star Strider
Star Strider 2018 年 4 月 20 日

Delete the single quotes, and add a ‘double equal’:

Tz=solve(Tz == (((xiz*(QH-deltaQH))./(M1.*(1+gammar)))+mcphayvc.*Tc)./(betaz.*mcphayphayvz), Tz)

That will at least not throw the same error.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 4 月 20 日
syms Ta Tc alpha gammar Tz xiz QH deltaQH M1 betaz
mcv=19.806+(0.00419/2).*Ta 
mcphayphayvz=19.806+(0.00419/2).*Tz+0.5.*Tz.*((360.34+252.4*alpha)^(10^-5))
mcphayvc=(mcv+gammar.*mcphayphayvz)./(1+gammar) 
eqn = Tz==(((xiz*(QH-deltaQH))./(M1.*(1+gammar)))+mcphayvc.*Tc)./(betaz.*mcphayphayvz);
Tzsol = solve(eqn, Tz)

Note that Ta Tc gammar must be scalar values for this purpose. If they were arrays then the solve() would be trying to find one single Tz that solved all of the values simultaneously.

If you are trying to get a solution for each corresponding Ta, Tc, gammar, then you can

subs(Tzsol, {Ta, Tc, gammar}, {Ta_array, Tc_array, gammar_array})

Also note that a pair of solutions are found. It looks like it might be two solutions for a quadratic.

  4 件のコメント
Vuong Hoang
Vuong Hoang 2018 年 4 月 21 日
編集済み: Vuong Hoang 2018 年 4 月 21 日

Thx for advices. I tried specific value (row 1,column 5401) in Ta,Tc,gammar,betaz(also an array) and get 'sub2ind -> out of range subscript error'. I doubt my equation is never satisfied.

 %code: 
syms Tz
mcv=19.806+(0.00419/2).*Ta(1,5401)
mcphayphayvz=19.806+(0.00419/2).*Tz+0.5.*Tz.*((360.34+252.4*alpha)^(10^-5))
mcphayvc=(mcv+gammar(1,5401).*mcphayphayvz)./(1+gammar(1,5401)) 
eqn = Tz==(((xiz*(QH-deltaQH))/(M1*(1+gammar(1,5401))))+mcphayvc*Tc(1,5401))/(betaz(1,5401).*mcphayphayvz);
Tzsol = solve(eqn, Tz)
Tz = double(Tzsol);
Walter Roberson
Walter Roberson 2018 年 4 月 21 日

If betaz is an array then you need to

syms Ta_s Tc_s alpha gammar_s Tz xiz QH deltaQH M1 betaz_s
mcv=19.806+(0.00419/2).*Ta_s 
mcphayphayvz=19.806+(0.00419/2).*Tz+0.5.*Tz.*((360.34+252.4*alpha)^(10^-5))
mcphayvc=(mcv+gammar_s.*mcphayphayvz)./(1+gammar_s) 
eqn = Tz==(((xiz*(QH-deltaQH))./(M1.*(1+gammar_s)))+mcphayvc.*Tc_s)./(betaz_s.*mcphayphayvz);
Tzsol = solve(eqn, Tz)
Tz = double( subs(Tzsol, {Ta_s, Tc_s, gammar_s, betaz_s}, {Ta, Tc, gammar, betaz}) );

If you only want one particular location you could

Tz5401 = double( subs(Tzsol, {Ta_s, Tc_s, gammar_s, betaz_s}, {Ta(5401), Tc(5401), gammar(5401), betaz(5401)}) );

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by