How to solve for all 5 values of x?

4 ビュー (過去 30 日間)
Mary Jean Savitsky
Mary Jean Savitsky 2020 年 4 月 10 日
コメント済み: Star Strider 2020 年 4 月 10 日
T= (473:50:673);
K=exp(21.225+(9143.6./T)-(7.492*log(T))+((4.076*10^-3)*(T))-(7.161*10^-8).*(T).^2);
syms x
function
eqn= ((100*x-2*x^2)/(1625-115*x+2*x^2))==K(1)*(5476);
solx= solve(eqn,x)
I want to solve for all the different values of x (there should be 5) using each different value of K. I tried just using K as a variable but gave me an error so I was going to do each individual K using K(1), K(2), etc. but it gives me a funciton instead of a value. please help!

採用された回答

Star Strider
Star Strider 2020 年 4 月 10 日
I would use a loop:
T= (473:50:673);
K=exp(21.225+(9143.6./T)-(7.492*log(T))+((4.076*10^-3)*(T))-(7.161*10^-8).*(T).^2);
syms x
for m = 1:numel(K)
eqn= ((100*x-2*x^2)/(1625-115*x+2*x^2))==K(m)*(5476);
solx(:,m) = vpasolve(eqn,x);
end
to store the results as columns of ‘solx’.
If you want to use them in numeric applications, use:
soln = double(solx);
  2 件のコメント
Mary Jean Savitsky
Mary Jean Savitsky 2020 年 4 月 10 日
thats perfect! the only problem is if I run it and display the solution, it gives it 5 times repeated. Is there anyway I can get it to just show once?
Star Strider
Star Strider 2020 年 4 月 10 日
Thank you!
I don’t understand. The ‘solx’ and ‘soln’ matrices are (2x5), with every column being a solution for a different value of ‘T’. (This is true in R2020a, however it should be the same in recent earlier releases as well.)
To plot them:
figure
plot(T, soln)
grid
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by