How do I plot the relationship between two variables in an inseparable function?
조회 수: 8 (최근 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?
댓글 수: 0
채택된 답변
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
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
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]);
댓글 수: 0
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])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!