Solving/plotting a nonlinear equation for multiple values
Afficher commentaires plus anciens
Hello all,
I am a mechanical engineering student working on some Applied Thermodynamics homework and am having trouble getting the values I need to plot a nonlinear equation. I have (on paper) determined that my nonlinear equation is as follow:
2*sqrt(P)*((x)^1.5) + .10905*x- 0.0363 = 0
where P is a pressure and x happens to be a molecular concentration in this case. So, I can solve the above equation for set values of P using the following function file (when P = 1).
function [x,P] = myfun(x)
F = 2*sqrt(1)*((x)^1.5) + .10905*x- 0.03635;
end
and the commands:
x0 = 0.5;
[x,fval] = fsolve(@myfun,x0)
But what I want is to define P as an array like [0.1:0.1:100] and be able to solve all of those values at once instead of having to get each one individually. I was wondering if this was possible using the above approach or if I should be looking at another method. Thank you in advance for any guidance you can give me. Still kind of a Matlab novice if you couldn't already tell.
Réponse acceptée
Plus de réponses (1)
Alfonso Nieto-Castanon
le 26 Nov 2013
Modifié(e) : Alfonso Nieto-Castanon
le 26 Nov 2013
Perhaps something like:
f = @(x,P)2*sqrt(P)*x^1.5 + .10905*x- 0.0363;
P = .1:.1:100;
x0 = 0.1;
[x,fval] = arrayfun(@(P)fzero(@(x)f(x,P),x0), P);
plot(P,x);
Catégories
En savoir plus sur Thermal Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!