How do I plot the relationship between two variables in an inseparable function?
12 views (last 30 days)
Show older comments
Dimitri Kaviani
on 8 Oct 2016
Commented: Walter Roberson
on 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 Comments
Accepted Answer
Renato Medeiros
on 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 Comments
Walter Roberson
on 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);
More Answers (2)
Massimo Zanetti
on 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 Comments
Walter Roberson
on 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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!