How do I plot the relationship between two variables in an inseparable function?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dimitri Kaviani
le 8 Oct 2016
Commenté : Walter Roberson
le 11 Oct 2016
I am trying to plot the relationship between the variables S and t in the following equation:
S = 8-0.7*t+2.5*log(8/S)
However, I do not know how to create a plot of S vs t given that the function is inseparable. What is the syntax in Matlab for plotting a function of more than one variable?
0 commentaires
Réponse acceptée
Renato Medeiros
le 8 Oct 2016
I guess you are trying to solve the implicit equation S = 8-0.7*t+2.5*log(8/S) and plot the result. If this is the case, you could solve for S after you determine a range for t. For this, you can use the function fsolve, passing the specified t as a parameter at each new solution, like:
function answer
%solve implicit function and plot
npoints = 100;
t = linspace(0.1,10,npoints);
S = zeros(1,npoints);
guess = 10;
for i = 1:npoints
S(i) = fzero(@equation,guess,[],t(i));
guess = S(i);
end
plot(t,S)
xlabel('t')
ylabel('S')
function dy = equation(S,t)
dy = 8-0.7*t+2.5*log(8/S) - S;
2 commentaires
Walter Roberson
le 11 Oct 2016
Renato is showing an undocumented syntax of fzero that could go away.
The call should be
S(i) = fzero(@(s) equation(s,t(i)), guess);
Plus de réponses (2)
Massimo Zanetti
le 9 Oct 2016
(Erroneously canceled my previous answer) Not all s,T verify the equation. To find them use fsolve https://it.mathworks.com/help/optim/ug/fsolve.html
To just plot, you need to see the equation as a surface of t,s as follows:
t=-2:.1:2;
s=0:.1:5;
[T,S]=meshgrid(t,s);
F = 8-0.7*T+2.5*log(8./S)-S;
surf(T,S,F);
xlabel('t');
label('S');
You can also look at the points that verify the equation by
contour(F,[0,0]);
0 commentaires
Walter Roberson
le 9 Oct 2016
The equations are separable:
t = 80/7+(25/7)*ln(8/S)-(10/7)*S
or
S = (5/2)*LambertW((16/5)*exp(16/5-(7/25)*t))
There are additional complex solutions for S, all of the other branches of LambertW; you did not specify the solution domain
You can also plot directly:
ezplot(@(t,S) -S + 8 - 0.7 .* t + 2.5 .* log(8./S), [-10 10])
0 commentaires
Voir également
Catégories
En savoir plus sur Vector Fields 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!