How to solve for all 5 values of x?

4 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 10 Apr 2020
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 Comments
Mary Jean Savitsky
Mary Jean Savitsky on 10 Apr 2020
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 on 10 Apr 2020
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
.

Sign in to comment.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!