hey guys,
i hav being trying for a very long time to design a c++ programme that solves second order differential equations as a final year proj. I got some codes from the resource material i have been working with; i keep getting errors compiling the codes.
pls i need help debuging this errors. i use visual studio pro edition.
Below is the error:
1>Code10.obj :
error LNK2019: unresolved external symbol "double __cdecl parse(class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,int,double * const,int * const)" (?parse@@YANV?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@HQANQAH@Z) referenced in function "public: void __thiscall CCode10::ODE1RK2(void)" (?ODE1RK2@CCode10@@QAEXXZ)
Below is the source code:(Header code)
<br />#include <afxwin.h><br />#include <afxcmn.h><br />#include <math.h><br />#define M 200<br />#define IDC_BUTTON 501<br />#define maxInput 11<br />#define nMenuItems 8<br /> <br />extern double parse(CString,int,double [],int []);<br /><br />class CCode10 : public CFrameWnd<br />{<br />protected:<br /> typedef struct<br /> {<br /> double x,y,p,z; // components<br /> } PT;<br /> PT *pt;<br /> typedef struct<br /> {<br /> CString item,label; // input string and its label<br /> CPoint hm; // home coordinates<br /> CEdit ed; // edit box<br /> CRect rc; // rectangular region<br /> } INPUT;<br /> INPUT input[maxInput+1];<br /> typedef struct<br /> {<br /> CString item; // menu item<br /> CPoint hm; // home coordinates<br /> CRect rc; // rectangular region<br /> } MENU;<br /> MENU menu[nMenuItems+1];<br /> typedef struct<br /> {<br /> CRect rc; // rectangular region<br /> CPoint hm,end; // starting and end coordinates<br /> } CURVE;<br /> CURVE curve;<br /> CListCtrl table;<br /> CFont Arial80;<br /> CButton btn;<br /> int m,idc,nInputItems,fMenu,fStatus;<br />public:<br /> CCode10();<br /> ~CCode10();<br /> void ODE1RK2(),ODE1RK4(),ODE1System();<br /> void ODE1Taylor(),ODE1AB(),ODE2toODE1System();<br /> void ODE2FD1(),ODE2FD2(),SolveSLE(double **,double *);<br /> void DrawCurve(),ShowTable(),Clear(CRect);<br /> afx_msg void OnPaint(),OnLButtonDown(UINT,CPoint);<br /> afx_msg void OnButton();<br /> DECLARE_MESSAGE_MAP()<br />};<br /><br />class CMyWinApp : public CWinApp<br />{<br />public:<br /> virtual BOOL InitInstance();<br />};</code><br /><br /><br />and the c++ code:<br /><br /><code>#include "Code10.h"<br />CMyWinApp MyApplication;<br />BOOL CMyWinApp::InitInstance()<br />{<br /> CCode10* pFrame = new CCode10;<br /> m_pMainWnd = pFrame;<br /> pFrame->ShowWindow(SW_SHOW);<br /> pFrame->UpdateWindow();<br /> return TRUE;<br />}<br /><br />BEGIN_MESSAGE_MAP(CCode10,CFrameWnd)<br /> ON_WM_PAINT()<br /> ON_WM_LBUTTONDOWN()<br /> ON_BN_CLICKED(IDC_BUTTON,OnButton)<br />END_MESSAGE_MAP()<br /><br />CCode10::CCode10()<br />{ <br /> Create(NULL,"Code10: Ordinary Differential Equations",<br /> WS_OVERLAPPEDWINDOW,CRect(0,0,800,635),NULL);<br /> Arial80.CreatePointFont(80,"Arial");<br /> pt=new PT [M+1];<br /> fMenu=0; fStatus=0; idc=301;<br /> curve.hm=CPoint(330,320); curve.end=CPoint(750,570);<br /> curve.rc=CRect(curve.hm.x-10,curve.hm.y-10,<br /> curve.end.x+30,curve.end.y+10);<br /> menu[1].item="ODE 1: Taylor (Order 3)"; <br /> menu[2].item="ODE 1: Runge-Kutta 2";<br /> menu[3].item="ODE 1: Runge-Kutta 4"; <br /> menu[4].item="ODE 1: Adams-Bashforth";<br /> menu[5].item="ODE 1: System"; <br /> menu[6].item="ODE 2: Initial Value Problem";<br /> menu[7].item="ODE 2: Finite-Difference 1"; <br /> menu[8].item="ODE 2: Finite-Difference 2";<br /> for (int i=1;i<=nMenuItems;i++)<br /> {<br /> menu[i].hm=CPoint(20,30+(i-1)*30);<br /> menu[i].rc=CRect(menu[i].hm.x,menu[i].hm.y,<br /> menu[i].hm.x+150,menu[i].hm.y+20);<br /> }<br /> input[0].hm=CPoint(200,10);<br /> input[0].rc=CRect(input[0].hm.x,input[0].hm.y,<br /> input[0].hm.x+560,input[0].hm.y+280);<br /> for (int i=1;i<=maxInput;i++)<br /> input[i].hm=CPoint(input[0].hm.x+10,input[0].hm.y+30+(i-1)*25);<br />}<br /><br />CCode10::~CCode10()<br />{ <br /> delete pt;<br />}<br /><br />void CCode10::OnPaint()<br />{<br /> <br /> CPaintDC dc(this);<br /> CString str;<br /> dc.SelectObject(Arial80);<br /> dc.SetBkColor(RGB(150,150,150));<br /> dc.SetTextColor(RGB(255,255,255));<br /> for (int i=1;i<=nMenuItems;i++)<br /> {<br /> dc.FillSolidRect(&menu[i].rc,RGB(150,150,150));<br /> dc.TextOut(menu[i].hm.x+5,menu[i].hm.y+5,menu[i].item);<br /> }<br /> dc.SetBkColor(RGB(255,255,255));<br /> dc.SetTextColor(RGB(100,100,100));<br /> dc.Rectangle(input[0].rc);<br /> dc.TextOut(input[0].hm.x+150,input[0].hm.y+5,menu[fMenu].item);<br /> if (fMenu>0)<br /> {<br /> for (int i=1;i<=nInputItems;i++)<br /> dc.TextOut(input[i].hm.x+10,input[i].hm.y,input[i].label);<br /> if (fStatus==2)<br /> {<br /> DrawCurve();<br /> fStatus=1;<br /> }<br /> }<br /> if (fMenu==2)<br /> dc.TextOut(input[6].hm.x+10,input[6].hm.y,input[6].label);<br /> if (fMenu==7)<br /> dc.TextOut(input[0].hm.x+300,input[0].hm.y+5,<br /> "p(x) y\"+q(x) y'+r(x) y = w(x), x[0]<=x<=x[m]");<br /> if (fMenu==8)<br /> dc.TextOut(input[0].hm.x+300,input[0].hm.y+5,<br /> "p(x) y\"+q(x) y'+r(x) y = w(x), x[0]<=x<=x[m]");<br />}<br /><br />void CCode10::DrawCurve()<br />{<br /> CClientDC dc(this);<br /> <br /> double m1,m2,c1,c2;<br /> CString str;<br /> CPoint px,px2;<br /> PT top,bottom,max,min,left,right;<br /> Clear(curve.rc);<br /> left.x=pt[0].x; right.x=pt[m].x;<br /> left.y=pt[0].y;<br /> max.y=pt[0].y; min.y=pt[0].y;<br /> <br /> if (fMenu==5)<br /> {<br /> max.z=pt[0].z; <br /> min.z=pt[0].z;<br /> }<br /> for (int i=0;i<=m;i++)<br /> {<br /> if (max.y<pt[i].y)<br /> max.y=pt[i].y; <br /> if (min.y>pt[i].y)<br /> min.y=pt[i].y;<br /> if (fMenu==5)<br /> {<br /> if (max.z<pt[i].z)<br /> max.z=pt[i].z;<br /> if (min.z>pt[i].z)<br /> min.z=pt[i].z;<br /> }<br /> }<br /> top.y=max.y; bottom.y=min.y;<br /> if (fMenu==5)<br /> {<br /> if (max.y<max.z)<br /> top.y=max.z;<br /> if (min.y>min.z)<br /> bottom.y=min.z;<br /> }<br /><br /> // Cartesian-Windows conversion coordinates<br /> m1=(double)(curve.end.x-curve.hm.x)/(right.x-left.x);<br /> c1=(double)curve.hm.x-left.x*m1;<br /> m2=(double)(curve.hm.y-curve.end.y)/(top.y-bottom.y);<br /> c2=(double)curve.end.y-bottom.y*m2;<br /><br /> // Draw & label the x,y axes<br /> CPen pGray(PS_SOLID,1,RGB(100,100,100));<br /> dc.SelectObject(pGray);<br /> dc.SelectObject(Arial80);<br /> px=CPoint(m1*0+c1,m2*bottom.y+c2); dc.MoveTo(px);<br /> px=CPoint(m1*0+c1,m2*top.y+c2); dc.LineTo(px);<br /> <br /> px=CPoint(m1*left.x+c1,m2*0+c2); dc.MoveTo(px);<br /> str.Format("%.0lf",left.x); dc.TextOut(px.x,px.y,str);<br /> px=CPoint(m1*right.x+c1,m2*0+c2); dc.LineTo(px);<br /> str.Format("%.0lf",right.x); dc.TextOut(px.x-10,px.y,str);<br /><br /> // draw the curve<br /> CPen pDark(PS_SOLID,2,RGB(50,50,50));<br /> dc.SelectObject(pDark);<br /> //str.Format("(%.1lf,%.1lf)",left.x,left.y);<br /> //dc.TextOut((int)(m1*left.x+c1),(int)(m2*left.y+c2),str);<br /> for (int i=0;i<=m;i++)<br /> {<br /> px=CPoint((int)(m1*pt[i].x+c1),(int)(m2*pt[i].y+c2));<br /> if (i==0)<br /> dc.MoveTo(px);<br /> else<br /> dc.LineTo(px);<br /> if (pt[i].y==top.y)<br /> {<br /> str.Format("%.3lf",top.y); <br /> dc.TextOut(px.x,px.y-10,str);<br /> }<br /> if (pt[i].y==bottom.y)<br /> {<br /> str.Format("%.3lf",bottom.y); <br /> dc.TextOut(px.x,px.y,str);<br /> }<br /> }<br /> if (fMenu==5)<br /> {<br /> CPen pLight(PS_SOLID,2,RGB(150,150,150));<br /> dc.SelectObject(pLight);<br /> for (int i=0;i<=m;i++)<br /> {<br /> px2=CPoint((int)(m1*pt[i].x+c1),(int)(m2*pt[i].z+c2));<br /> if (i==0)<br /> {<br /> dc.MoveTo(px2);<br /> dc.TextOut(px2.x+15,px2.y-10,"z=g(x)");<br /> }<br /> else<br /> dc.LineTo(px2);<br /> }<br /> }<br />}<br /><br />void CCode10::OnLButtonDown(UINT nFlags,CPoint pt)<br />{<br /> int i,k;<br /> for (k=1;k<=nMenuItems;k++)<br /> if (menu[k].rc.PtInRect(pt))<br /> {<br /> fMenu=k; fStatus=1;<br /> switch(k)<br /> {<br /> case 1: <br /> nInputItems=7; <br /> input[1].label="y'=g(x,y)";<br /> input[2].label="x[0]"; <br /> input[3].label="x[m]";<br /> input[4].label="h"; <br /> input[5].label="y[0]"; <br /> input[6].label="y'' (u=y')";<br /> input[7].label="y'''(v=y'')";<br /> break;<br /> case 2: <br /> nInputItems=6; <br /> input[1].label="y'=g(x,y)"; <br /> input[2].label="x[0]"; <br /> input[3].label="x[m]";<br /> input[4].label="h"; <br /> input[5].label="y[0]"; <br /> input[6].label="r (0<r<=1)";<br /> break;<br /> case 3: <br /> nInputItems=5; <br /> input[1].label="y'=g(x,y)"; <br /> input[2].label="x[0]"; <br /> input[3].label="x[m]";<br /> input[4].label="h"; <br /> input[5].label="y[0]"; <br /> break;<br /> case 4: <br /> nInputItems=5; <br /> input[1].label="y'=g(x,y)"; <br /> input[2].label="x[0]"; <br /> input[3].label="x[m]";<br /> input[4].label="h"; <br /> input[5].label="y[0]"; <br /> break;<br /> case 5: <br /> nInputItems=7; <br /> input[1].label="y'=f(x,y,z)"; <br /> input[2].label="z'=g(x,y,z)"; <br /> input[3].label="x[0]"; <br /> input[4].label="y[0]"; <br /> input[5].label="z[0]";<br /> input[6].label="h"; <br /> input[7].label="x[m]";<br /> break;<br /> case 6: <br /> nInputItems=6; <br /> input[1].label="y\"=f(x,y,z=y')"; <br /> input[2].label="x[0]"; <br /> input[3].label="y[0]"; <br /> input[4].label="z[0]=y'[0]";<br /> input[5].label="h"; <br /> input[6].label="x[m]";<br /> break;<br /> case 7: <br /> nInputItems=9; <br /> input[1].label="p(x)"; <br /> input[2].label="q(x)"; <br /> input[3].label="r(x)"; <br /> input[4].label="w(x)";<br /> input[5].label="h"; <br /> input[6].label="x[0]"; <br /> input[7].label="x[m]";<br /> input[8].label="y[0]"; <br /> input[9].label="y[m]";<br /> break;<br /> case 8: <br /> nInputItems=9; <br /> input[1].label="p(x)"; <br /> input[2].label="q(x)"; <br /> input[3].label="r(x)"; <br /> input[4].label="w(x)";<br /> input[5].label="h"; <br /> input[6].label="x[0]";<br /> input[7].label="x[m]"; <br /> input[8].label="y'[0]";<br /> input[9].label="y'[m]";<br /> break;<br /> }<br /> for (i=1;i<=maxInput;i++)<br /> input[i].ed.DestroyWindow();<br /> for (i=1;i<=nInputItems;i++)<br /> input[i].ed.Create(WS_CHILD| WS_VISIBLE| WS_BORDER, <br /> CRect(input[i].hm.x+100,input[i].hm.y,<br /> input[i].hm.x+520,input[i].hm.y+20),this,idc++);<br /> InvalidateRect(input[0].rc);<br /> Clear(curve.rc);<br /> table.DestroyWindow();<br /> btn.DestroyWindow();<br /> btn.Create("Compute",WS_CHILD| WS_VISIBLE| BS_DEFPUSHBUTTON,<br /> CRect(CPoint(input[0].hm.x+10,input[0].hm.y+5),<br /> CSize(100,20)),this,IDC_BUTTON);<br /> }<br />}<br /><br />void CCode10::ODE1RK2()<br />{<br /> int i,psi[6];<br /> double h,r,psv[6],tmp,max;<br /> double k1,k2;<br /> pt[0].x=atof(input[2].item); <br /> pt[0].y=atof(input[5].item);<br /> h=atof(input[4].item); <br /> tmp=atof(input[3].item); <br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> max=pt[0].x+(double)m*h;<br /> tmp=(tmp<max)?tmp:max;<br /> pt[m].x=tmp;<br /> r=atof(input[6].item);<br /> psi[1]=23; psi[2]=24;<br /> for (i=0;i<=m;i++)<br /> {<br /> psv[1]=pt[i].x;<br /> psv[2]=pt[i].y;<br /> k1=h*parse(input[1].item,2,psv,psi);<br /> psv[1]=pt[i].x+r*h;<br /> psv[2]=pt[i].y+r*k1;<br /> k2=h*parse(input[1].item,2,psv,psi);<br /> if (i<m)<br /> {<br /> pt[i+1].y=pt[i].y+(1-1/(2*r))*k1+1/(2*r)*k2;<br /> pt[i+1].x=pt[i].x+h;<br /> }<br /> }<br />}<br /><br />void CCode10::ODE1RK4()<br />{<br /> <br /> int i,psi[6];<br /> double h,psv[6],tmp,max;<br /> double k1,k2,k3,k4;<br /> pt[0].x=atof(input[2].item); <br /> pt[0].y=atof(input[5].item);<br /> h=atof(input[4].item); <br /> tmp=atof(input[3].item); <br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> max=pt[0].x+(double)m*h;<br /> tmp=(tmp<max)?tmp:max;<br /> pt[m].x=tmp;<br /> psi[1]=23; psi[2]=24;<br /> for (i=0;i<=m;i++)<br /> {<br /> psv[1]=pt[i].x;<br /> psv[2]=pt[i].y;<br /> k1=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k1/2;<br /> k2=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k2/2;<br /> k3=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h;<br /> psv[2]=pt[i].y+k3;<br /> k4=h*parse(input[1].item,2,psv,psi);<br /> if (i<m)<br /> {<br /> pt[i+1].y=pt[i].y+(k1+2*k2+2*k3+k4)/6;<br /> pt[i+1].x=pt[i].x+h;<br /> }<br /> }<br />}<br /><br />void CCode10::ShowTable()<br />{<br /> CString str;<br /> CPoint hTable=CPoint(20,310);<br /> CRect rcTable=CRect(hTable.x,hTable.y,hTable.x+280,hTable.y+290);<br /> table.DestroyWindow();<br /> table.Create(WS_VISIBLE | WS_CHILD | WS_DLGFRAME | LVS_REPORT<br /> | LVS_NOSORTHEADER,rcTable,this,idc++);<br /> table.InsertColumn(0,"i",LVCFMT_CENTER,25);<br /> table.InsertColumn(1,"x",LVCFMT_CENTER,70);<br /> table.InsertColumn(2,"y=f(x)",LVCFMT_CENTER,70);<br /> if (fMenu==4 || fMenu==5)<br /> table.InsertColumn(3,((fMenu==4)?"p":"z"),LVCFMT_CENTER,70);<br /> for (int i=0;i<=m;i++)<br /> {<br /> str.Format("%d",i); table.InsertItem(i,str,0);<br /> str.Format("%lf",pt[i].x); table.SetItemText(i,1,str);<br /> str.Format("%lf",pt[i].y); table.SetItemText(i,2,str);<br /> if (fMenu==4 && i>3)<br /> {<br /> str.Format("%lf",pt[i].p); <br /> table.SetItemText(i,3,str);<br /> }<br /> if (fMenu==5)<br /> {<br /> str.Format("%lf",pt[i].z); <br /> table.SetItemText(i,3,str);<br /> }<br /> }<br />}<br /><br />void CCode10::OnButton()<br />{<br /> if (fStatus==1)<br /> {<br /> for (int i=1;i<=nInputItems;i++)<br /> input[i].ed.GetWindowText(input[i].item);<br /> switch(fMenu)<br /> {<br /> case 1:<br /> ODE1Taylor(); fStatus=2; break;<br /> case 2:<br /> ODE1RK2(); fStatus=2; break;<br /> case 3:<br /> ODE1RK4(); fStatus=2; break;<br /> case 4:<br /> ODE1AB(); fStatus=2; break;<br /> case 5:<br /> ODE1System(); fStatus=2; break;<br /> case 6: <br /> ODE2toODE1System(); fStatus=2; break;<br /> case 7: <br /> ODE2FD1(); fStatus=2; break;<br /> case 8: <br /> ODE2FD2(); fStatus=2; break;<br /> }<br /> }<br /> if (fStatus=2)<br /> {<br /> ShowTable(); <br /> InvalidateRect(curve.rc);<br /> }<br />}<br /><br />void CCode10::ODE1System()<br />{<br /> <br /> int i,psi[6];<br /> double h,psv[6],tmp,max;<br /> double k1,k2,k3,k4;<br /> double K1,K2,K3,K4;<br /> pt[0].x=atof(input[3].item); <br /> pt[0].y=atof(input[4].item); <br /> pt[0].z=atof(input[5].item);<br /> h=atof(input[6].item); <br /> tmp=atof(input[7].item);<br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> max=pt[0].x+(double)m*h;<br /> tmp=(tmp<max)?tmp:max;<br /> pt[m].x=tmp;<br /> psi[1]=23; psi[2]=24; psi[3]=25;<br /> for (i=0;i<=m;i++)<br /> {<br /> psv[1]=pt[i].x;<br /> psv[2]=pt[i].y;<br /> psv[3]=pt[i].z;<br /> k1=h*parse(input[1].item,3,psv,psi); <br /> K1=h*parse(input[2].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k1/2;<br /> psv[3]=pt[i].z+K1/2;<br /> k2=h*parse(input[1].item,3,psv,psi); <br /> K2=h*parse(input[2].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k2/2;<br /> psv[3]=pt[i].z+K2/2;<br /> k3=h*parse(input[1].item,3,psv,psi); <br /> K3=h*parse(input[2].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h;<br /> psv[2]=pt[i].y+k3;<br /> psv[3]=pt[i].z+K3;<br /> k4=h*parse(input[1].item,3,psv,psi); <br /> K4=h*parse(input[2].item,3,psv,psi);<br /><br /> if (i<m)<br /> {<br /> pt[i+1].y=pt[i].y+(k1+2*k2+2*k3+k4)/6;<br /> pt[i+1].z=pt[i].z+(K1+2*K2+2*K3+K4)/6;<br /> pt[i+1].x=pt[i].x+h;<br /> }<br /> }<br />}<br /><br />void CCode10::ODE1Taylor()<br />{<br /> double psv[6],tmp,max;<br /> int psi[6];<br /> int i;<br /> double h,u,v,w,z;<br /><br /> pt[0].x=atof(input[2].item); <br /> pt[0].y=atof(input[5].item);<br /> h=atof(input[4].item); <br /> tmp=atof(input[3].item); <br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> max=pt[0].x+(double)m*h;<br /> tmp=(tmp<max)?tmp:max;<br /> pt[m].x=tmp;<br /> psi[1]=23; psi[2]=24;<br /> psi[3]=20; psi[4]=21; //psi[5]=22;<br /> for (i=0;i<=m;i++)<br /> {<br /> psv[1]=pt[i].x; <br /> psv[2]=pt[i].y; <br /> u=parse(input[1].item,2,psv,psi); <br /> psv[3]=u; <br /> v=parse(input[6].item,3,psv,psi); <br /> psv[4]=v; <br /> w=parse(input[7].item,4,psv,psi);<br /> if (i<m)<br /> {<br /> pt[i+1].y=pt[i].y+h*u+pow(h,2)/2*v+pow(h,3)/6*w;<br /> pt[i+1].x=pt[i].x+h;<br /> }<br /> }<br />}<br /><br />void CCode10::ODE1AB()<br />{<br /> <br /> int i,psi[6];<br /> double h,f0,f1,f2,f3,fp,psv[6],tmp,max;<br /> double k1,k2,k3,k4;<br /> pt[0].x=atof(input[2].item); pt[0].y=atof(input[5].item);<br /> h=atof(input[4].item); <br /> tmp=atof(input[3].item); <br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> max=pt[0].x+(double)m*h;<br /> tmp=(tmp<max)?tmp:max;<br /> pt[m].x=tmp;<br /> psi[1]=23; psi[2]=24;<br /> for (i=0;i<=m;i++)<br /> {<br /> if (i<3)<br /> {<br /> psv[1]=pt[i].x;<br /> psv[2]=pt[i].y;<br /> k1=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k1/2;<br /> k2=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k2/2;<br /> k3=h*parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x+h;<br /> psv[2]=pt[i].y+k3;<br /> k4=h*parse(input[1].item,2,psv,psi);<br /><br /> pt[i+1].y=pt[i].y+(k1+2*k2+2*k3+k4)/6;<br /> }<br /> if (i<m)<br /> {<br /> pt[i+1].x=pt[i].x+h;<br /> if (i>=3)<br /> {<br /> psv[1]=pt[i-3].x;<br /> psv[2]=pt[i-3].y;<br /> f0=parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i-2].x;<br /> psv[2]=pt[i-2].y;<br /> f1=parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i-1].x;<br /> psv[2]=pt[i-1].y;<br /> f2=parse(input[1].item,2,psv,psi);<br /><br /> psv[1]=pt[i].x; <br /> psv[2]=pt[i].y; <br /> f3=parse(input[1].item,2,psv,psi);<br /> pt[i+1].p=pt[i].y+h/24*(-9*f0+37*f1-59*f2+55*f3);<br /><br /> psv[1]=pt[i+1].x;<br /> psv[2]=pt[i+1].p;<br /> fp=parse(input[1].item,2,psv,psi);<br /> pt[i+1].y=pt[i].y+h/24*(f1-5*f2+19*f3+9*fp);<br /> }<br /> }<br /> }<br />}<br /><br />void CCode10::ODE2toODE1System()<br />{<br /> <br /> int i,psi[6];<br /> double psv[6];<br /> double h,tmp;<br /> double k1,k2,k3,k4;<br /> double K1,K2,K3,K4;<br /> pt[0].x=atof(input[2].item); <br /> pt[0].y=atof(input[3].item); <br /> pt[0].z=atof(input[4].item);<br /> h=atof(input[5].item); <br /> tmp=atof(input[6].item); <br /> m=(tmp-pt[0].x)/h; m=((m<M)?m:M);<br /> pt[m].x=tmp;<br /> psi[1]=23; psi[2]=24; psi[3]=25;<br /> for (i=0;i<=m;i++)<br /> {<br /> psv[1]=pt[i].x;<br /> psv[2]=pt[i].y;<br /> psv[3]=pt[i].z;<br /> k1=h*pt[i].z; K1=h*parse(input[1].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2;<br /> psv[2]=pt[i].y+k1/2;<br /> psv[3]=pt[i].z+K1/2;<br /> k2=h*(pt[i].z+K1/2); K2=h*parse(input[1].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h/2; <br /> psv[2]=pt[i].y+k2/2;<br /> psv[3]=pt[i].z+K2/2;<br /> k3=h*(pt[i].z+K2/2); K3=h*parse(input[1].item,3,psv,psi);<br /><br /> psv[1]=pt[i].x+h; <br /> psv[2]=pt[i].y+k3;<br /> psv[3]=pt[i].z+K3;<br /> k4=h*(pt[i].z+K3); K4=h*parse(input[1].item,3,psv,psi);<br /><br /> if (i<m)<br /> {<br /> pt[i+1].y=pt[i].y+(k1+2*k2+2*k3+k4)/6;<br /> pt[i+1].z=pt[i].z+(K1+2*K2+2*K3+K4)/6;<br /> pt[i+1].x=pt[i].x+h;<br /> }<br /> }<br />}<br /><br />void CCode10::ODE2FD1()<br />{<br /> <br /> int i,j,psi[6];<br /> double psv[6],h,tmp;<br /> double **a,*b;<br /> double *p,*q,*r,*w;<br /> b=new double [M+1];<br /> p=new double [M+1];<br /> q=new double [M+1];<br /> r=new double [M+1];<br /> w=new double [M+1];<br /> a=new double *[M+1];<br /> h=atof(input[5].item);<br /> m=(int)(atof(input[7].item)-atof(input[6].item))/h; m=((m<M)?m:M);<br /> pt[0].x=atof(input[6].item); <br /> pt[m].x=pt[0].x+(double)m*h;<br /> pt[0].y=atof(input[8].item); <br /> pt[m].y=atof(input[9].item);<br /> psi[1]=23;<br /> for (i=1;i<=m-1;i++)<br /> {<br /> pt[i].x=pt[i-1].x+h;<br /> psv[1]=pt[i].x; <br /> p[i]=parse(input[1].item,1,psv,psi);<br /> q[i]=parse(input[2].item,1,psv,psi);<br /> r[i]=parse(input[3].item,1,psv,psi);<br /> w[i]=parse(input[4].item,1,psv,psi);<br /> }<br /> for (i=0;i<=M;i++)<br /> a[i]=new double [M+1];<br /> for (i=1;i<=m-1;i++)<br /> {<br /> for (j=1;j<=m-1;j++)<br /> a[i][j]=0;<br /> b[i]=0;<br /> }<br /> b[1]=w[1]-(p[1]/(h*h)-q[1]/(2*h))*pt[0].y;<br /> b[m-1]=w[m-1]-(p[m-1]/(h*h)+q[m-1]/(2*h))*pt[m].y;<br /> for (i=1;i<=m-1;i++)<br /> {<br /> a[i][i]=-2*p[i]/(h*h)+r[i];<br /> if (i<m-1)<br /> a[i+1][i]=p[i+1]/(h*h)-q[i+1]/(2*h);<br /> if (i>1)<br /> a[i-1][i]=p[i-1]/(h*h)+q[i-1]/(2*h);<br /> if (i>1 && i<m-1)<br /> b[i]=w[i];<br /> }<br /> SolveSLE(a,b);<br /> for (i=0;i<=M;i++)<br /> delete a[i];<br /> delete p,q,r,w,a,b;<br />}<br /><br />void CCode10::SolveSLE(double **a,double *b)<br />{<br /> int i,j,k,lo,hi;<br /> double m1,Sum;<br /> if (fMenu==7)<br /> {<br /> lo=1; hi=m-1;<br /> }<br /> if (fMenu==8)<br /> {<br /> lo=0; hi=m;<br /> }<br /> for (k=lo;k<=hi-1;k++)<br /> for (i=k+1;i<=hi;i++)<br /> {<br /> m1=a[i][k]/a[k][k];<br /> for (j=lo;j<=hi;j++)<br /> a[i][j] -= m1*a[k][j];<br /> b[i] -= m1*b[k];<br /> }<br /> for (i=hi;i>=lo;i--)<br /> {<br /> Sum=0;<br /> pt[i].y=0;<br /> for (j=i;j<=hi;j++)<br /> Sum += a[i][j]*pt[j].y;<br /> pt[i].y=(b[i]-Sum)/a[i][i];<br /> }<br />}<br /><br />void CCode10::ODE2FD2()<br />{<br /> <br /> int i,j,psi[6];<br /> double psv[6],tmp;<br /> double h,alpha,beta;<br /> double **a,*b;<br /> double *p,*q,*r,*w;<br /> b=new double [M+1];<br /> p=new double [M+1];<br /> q=new double [M+1];<br /> r=new double [M+1];<br /> w=new double [M+1];<br /> a=new double *[M+1];<br /> for (i=0;i<=M;i++)<br /> a[i]=new double [M+1];<br /> h=atof(input[5].item);<br /> m=(int)(atof(input[7].item)-atof(input[6].item))/h; m=((m<M)?m:M);<br /> pt[0].x=atof(input[6].item); <br /> pt[m].x=pt[0].x+(double)m*h;<br /> alpha=atof(input[8].item); beta=atof(input[9].item); <br /> for (i=0;i<=m;i++)<br /> {<br /> if (i<m)<br /> pt[i+1].x=pt[i].x+h;<br /> psv[1]=pt[i].x; psi[1]=23;<br /> p[i]=parse(input[1].item,1,psv,psi);<br /> q[i]=parse(input[2].item,1,psv,psi);<br /> r[i]=parse(input[3].item,1,psv,psi);<br /> w[i]=parse(input[4].item,1,psv,psi);<br /> }<br /> for (i=0;i<=m;i++)<br /> {<br /> for (j=0;j<=m;j++)<br /> a[i][j]=0;<br /> b[i]=0;<br /> }<br /> for (i=0;i<=m;i++)<br /> {<br /> a[i][i]=-2*p[i]/(h*h)+r[i];<br /> if (i>0 && i<m)<br /> a[i][i+1]=p[i]/(h*h)+q[i]/(2*h);<br /> if (i<m-1)<br /> a[i+1][i]=p[i+1]/(h*h)-q[i+1]/(2*h);<br /> if (i>0 && i<m)<br /> b[i]=w[i];<br /> }<br /> a[0][1]=2*p[0]/m;<br /> a[m][m-1]=2*p[m]/(h*h);<br /> b[0]=w[0]+(p[0]/(h*h)-q[0]/(2*h))*2*h*alpha;<br /> b[m]=w[m]-(p[m]/(h*h)+q[m]/(2*h))*2*h*beta;<br /> SolveSLE(a,b);<br /> for (i=0;i<=M;i++)<br /> delete a[i];<br /> delete p,q,r,w,a,b;<br />}<br /><br />void CCode10::Clear(CRect rc)<br />{<br /> CClientDC dc(this);<br /> CBrush whiteBrush(RGB(255,255,255));<br /> dc.FillRect(&rc,&whiteBrush);<br />}