How do I plot the relationship between two variables in an inseparable function?

9 次查看(过去 30 天)
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?

采纳的回答

Renato Medeiros
Renato Medeiros 2016-10-8
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 个评论
Dimitri Kaviani
Dimitri Kaviani 2016-10-11
Can you explain the syntax of the fzero command? I understand that you are required to input the function and an initial guess but what are the other inputs you have listed above?
Walter Roberson
Walter Roberson 2016-10-11
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);

请先登录,再进行评论。

更多回答(2 个)

Massimo Zanetti
Massimo Zanetti 2016-10-9
(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]);

Walter Roberson
Walter Roberson 2016-10-9
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])

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by