not sure if this is the right place to ask, but i need some help for my problem here.
i want to find inverse, upper triangular and determinant for a matrix. but i'm not sure why it doesn't work like what i want. for now, i just want try to find determinant.
here's what i've done, if someone can point out my mistake, it'll be great help.
this is in header file
#include <afxwin.h>
#define IDC_BUTTON 201
#define IDC_a 205
#define IDC_a1 207
#define IDC_a2 208
#define IDC_a3 209
#define N 2
class CA2 : public CFrameWnd
{
private:
double a3;
double a[N+1][N+1], a1[N+1][N+1], a2[N+1][N+1];
CEdit ea[N+1][N+1];
CStatic sa1[N+1][N+1], sa2[N+1][N+1], sa3;
//CButton MyButton;
//CButton Inverse;
CButton bZ[4];
public:
CA2();
~CA2() {}
afx_msg void OnInverse();
afx_msg void OnUpperTri();
afx_msg void OnDeterminant();
DECLARE_MESSAGE_MAP()
};
class CMyWinApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
CMyWinApp MyApplication;
BOOL CMyWinApp::InitInstance()
{
m_pMainWnd = new CA2;
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}
this is in cpp file:
#include "A2.h"
BEGIN_MESSAGE_MAP(CA5,CFrameWnd)
ON_BN_CLICKED (IDC_BUTTON, OnInverse)
ON_BN_CLICKED (IDC_BUTTON,OnUpperTri)
ON_BN_CLICKED (IDC_BUTTON, OnDeterminant)
END_MESSAGE_MAP()
CA2::CA2()
{
int i, j;
CString bTitle[4]={L"",L"Inverse",L"UpperTriangular",L"Determinant"};
Create(NULL,L"A2: A Matrix Calculator",
WS_OVERLAPPEDWINDOW,CRect(0,0,1150,700));
//input for matrix A in edit boxes
for (i=1; i<=N; i++)
for (j=1; j<=N; j++)
{
ea[i][j].Create(WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(CPoint(30+100*(j-1),80+40*(i-1)),CSize(70,25)),this,IDC_a);
}
//button for a1,a2&a3
for (i=1; i<=3; i++)
bZ[i].Create(bTitle[i],WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
CRect(CPoint(150,350+40*(i-1)),CSize(180,25)),this,IDC_BUTTON);
//output for inverse, uppertriangular, determinant of matrix A
for (i=1; i<=N; i++)
for (j=1; j<=N; j++)
{
sa1[i][j].Create(L"",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(CPoint(600+100*(j-1),80+40*(i-1)),CSize(70,25)),this,IDC_a1);
}
for (i=1; i<=N; i++)
for (j=1; j<=N; j++)
{
sa2[i][j].Create(L"",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(CPoint(600+100*(j-1),350+40*(i-1)),CSize(70,25)),this,IDC_a2);
}
sa3.Create(L" ",WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER,
CRect(CPoint(750,600),CSize(140,25)),this,IDC_a3);
ea[1][1].SetFocus();
}
void CA2::OnInverse()
{
}
void CA2::OnUpperTri()
{
}
void CA2::OnDeterminant()
{
int i,j,k;
CString s;
for (i=1; i<=N; i++)
for (j=1; j<=N; j++)
{
ea[i][j].GetWindowText(s); a[i][j]=_tstof(s);
}
//ea[6][6].GetWindowText(s); a[6][6]=_tstof(s);
//row operations
//a3=product
double m;
for (k=1; k<=N-1; k++)
for (i=k+1; i<=N; i++)
{
m=a[i][k]/a[k][k];
for (j=1; j<=2; j++)
a[i][j]-=m*a[k][j];
}
a3=1;
for (i=1; i<=N; i++)
a3 *=a[i][i];
s.Format(L"=%lf", a3); sa3.SetWindowText(s);
}