How to solve for all 5 values of x?

4 vues (au cours des 30 derniers jours)
Mary Jean Savitsky
Mary Jean Savitsky le 10 Avr 2020
Commenté : Star Strider le 10 Avr 2020
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!

Réponse acceptée

Star Strider
Star Strider le 10 Avr 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 commentaires
Mary Jean Savitsky
Mary Jean Savitsky le 10 Avr 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 le 10 Avr 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
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by