common tangent of two curves with vpasolve.
5 views (last 30 days)
Show older comments
muhsin ider
on 8 Jun 2020
Commented: muhsin ider
on 12 Jun 2020
The following code finds common tangents of fx and gx by symbolic expressions. I used first "solve" but sometimes it can not find all the roots of the denk1 and denk2 which are derived from common tangent geometry. vpasolve finds a pair of x,y but not both. I appreciate any help or suggestions.
best wishes,
clc, clear all, close all
disp([' (t) a b']);
R=8.314 ;%j/mol K;
O1=-15000;
O2=0; %j/mol K;
for t=1300:50:1350
syms x fx gx ek m(x) y1(x) a b y2(x) f(x) g(x) fu(x) gu(x)
syms denk1 denk2 denk3 p yx
f(x)=R*t*((x*log(x))+((1-x)*log(1-x)))+O1*(x-x^2);
g(x)=x*(12000-10*t)+((1-x)*(8000-10*t))+R*t*((x*log(x))+((1-x)*log(1-x)));
fu(x)=diff(f(x),x);%1. differential
gu(x)=diff(g(x),x);%2.differential
denk1=(((g(b)-f(a))/(b-a))==(fu(a)));
denk2=(fu(a)==gu(b));
%[a b]=solve(denk1,denk2,a,b);
%[kola kolb] = vpasolve([denk1 denk2],[a b],[0.2;.99991])
[Sola Solb] = vpasolve([denk1 denk2],[a b],[0.1; 0.3]);
a=Sola;
b=Solb;
disp([t,a,b])
x=0:0.01:1;
plot(x ,f(x),'r-',x ,g(x),'-b')
hold on
p = linspace(a,b);
%y=mx+n graph of common tangent line between a and b
yx=((fu(a))*(p-a))+f(a);
plot(p,yx, 'm-')
pause(2)
hold off
figure
end
2 Comments
Accepted Answer
Bjorn Gustavsson
on 12 Jun 2020
In your code you gove starting-points for the variable you search for. Perhaps vpasolve doesn't bother to look for all solutions of your equation (in case they are too complex one solution might be considered good enough). Try to look for a second solution starting from another point (~0.8 and 0.9). If that gives you a second solution you've found the second solution. I've not looked at your equations to know how many solutions you should have...
HTH
7 Comments
Bjorn Gustavsson
on 12 Jun 2020
That is most likely a design-choise by Mathworks. If, for example, vpasolve were to try to return all solutions of equations there might be problems when you try to solve equations with infinitely many solutions. Then there would need to be some arbitrary cut-off when the number of solutions will be considered "enough". Perhaps Mathworks then made the choise that one solution is enough.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!