Mathematica : equivalent point

มีคนโพสท์ถามที่พันทิป http://pantip.com/topic/34236148

pt1

pt1

pt1

pt1

ผมได้ลองใช้ Mathematica เขียนแบบง่ายๆได้ตามนี้ครับ

pantipPlot

โดย code ที่เขียนก็ประมาณนี้ครับ



data={{0.,4.04},{1.,4.6},{2.,5.01},{3.,5.38},{4.,5.84},{4.5,6.31},{5.,9.99},{5.5,10.7},{6.,10.97},{6.5,11.12},{7.,11.22},{8.,11.35},{9.,11.44},{10.,11.51},{11.,11.57},{12.,11.62}};

SplitDat[np1_List,np2_List]:=Module[{dat1,dat2},
dat1=data[[np1[[1]];;np1[[2]]]];
dat2=data[[np2[[1]];;np2[[2]]]];
{dat1,dat2}
];

genLineEq[datsplitted_,x_]:=Module[{dat1,dat2,lm1,lm2},
dat1=datsplitted[[1]];
dat2=datsplitted[[2]];
lm1=LinearModelFit[dat1,x,x];
lm2=LinearModelFit[dat2,x,x];
{lm1,lm2}
];

pantipPlot1[pospnts1_List,pospnts2_List,verpos1_,verpos2_,wantx_]:=Module[{x,eq1,eq2,eq3,xx,wanty},
{eq1,eq2}=genLineEq[SplitDat[pospnts1,pospnts2],x];
eq3=Fit[{{verpos1,((eq2[verpos1]-eq1[verpos1])0.5)+eq1[verpos1]},{verpos2,((eq2[verpos2]-eq1[verpos2])0.5)+eq1[verpos2]}},{1,xx},xx];
wanty=eq3/.{xx->wantx};

Show[Plot[{eq1[x],eq2[x]},{x,0,14},PlotRange->{0,13},PlotLabel->Style["Standardization NaOH with KHP",Bold,Medium],Frame->True,FrameLabel->{"V of NaOH (ml)","pH of KHP"},GridLines->Automatic,GridLinesStyle->Directive[Dotted, Gray],PlotStyle->{{Dashed,Gray},{Dashed,Gray}}],ListPlot[data,Joined->True,PlotStyle->Blue,PlotMarkers->Automatic],
Graphics[{Dashed,Line[{{verpos1,eq1[verpos1]},{verpos1,eq2[verpos1]}}]}],
Graphics[{Dashed,Line[{{verpos2,eq1[verpos2]},{verpos2,eq2[verpos2]}}]}],
Graphics[{Red,Dashed,Line[{{verpos1,((eq2[verpos1]-eq1[verpos1])0.5)+eq1[verpos1]},{verpos2,((eq2[verpos2]-eq1[verpos2])0.5)+eq1[verpos2]}}]}],
Graphics[{{Red,Line[{{wantx,0},{wantx,wanty}}]},Text[wanty,{wantx,wanty},{-1,0}]}]
]
];

Manipulate[pantipPlot1[{1,endLine1},{begLine2,16},begVerLeft,begVerRight,xwant],
{{endLine1,6},2,8,1,Appearance->"Labeled"},{{begLine2,8},8,16,1,Appearance->"Labeled"},
{{begVerLeft,3},1,6,Appearance->"Labeled"},
{{begVerRight,5},4.5,13,Appearance->"Labeled"},
{xwant,0,12,Appearance->"Labeled"}
] 

%d bloggers like this: