How to solve for all 5 values of x?

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by