⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lagrange.txt

📁 拉格朗日插值程序,可用于进行一维插值计算.
💻 TXT
字号:
#include <windows.h> 
#include <string.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <math.h> 
#include <iostream> 

#define N 8 

/* Declare Windows procedure */ 
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 

/* Make the class name into a global variable */ 
char szClassName[ ] = "WindowsApp"; 

int WINAPI WinMain (HINSTANCE hThisInstance, 
HINSTANCE hPrevInstance, 
LPSTR lpszArgument, 
int nFunsterStil) 

{ 
HWND hwnd; /* This is the handle for our window */ 
MSG messages; /* Here messages to the application are saved */ 
WNDCLASSEX wincl; /* Data structure for the windowclass */ 

/* The Window structure */ 
wincl.hInstance = hThisInstance; 
wincl.lpszClassName = szClassName; 
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ 
wincl.style = CS_DBLCLKS; /* Catch double-clicks */ 
wincl.cbSize = sizeof (WNDCLASSEX); 

/* Use default icon and mouse-pointer */ 
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
wincl.hCursor = LoadCursor (NULL, IDC_ARROW); 
wincl.lpszMenuName = NULL; /* No menu */ 
wincl.cbClsExtra = 0; /* No extra bytes after the window class */ 
wincl.cbWndExtra = 0; /* structure or the window instance */ 
/* Use Windowss default color as the background of the window */ 
wincl.hbrBackground = (HBRUSH) /*GetStockObject(WHITE_BRUSH)*/COLOR_BACKGROUND; 

/* Register the window class, and if it fails quit the program */ 
if (!RegisterClassEx (&wincl)) 
{ 
MessageBeep(0); 
return 0; 
} 

/* The class is registered, lets create the program*/ 
hwnd = CreateWindowEx ( 
0, /* Extended possibilites for variation */ 
szClassName, /* Classname */ 
"061300814 于俊", /* Title Text */ 
WS_OVERLAPPEDWINDOW, /* default window */ 
CW_USEDEFAULT, /* Windows decides the position */ 
CW_USEDEFAULT, /* where the window ends up on the screen */ 
800, /* The programs width */ 
600, /* and height in pixels */ 
HWND_DESKTOP, /* The window is a child-window to desktop */ 
NULL, /* No menu */ 
hThisInstance, /* Program Instance handler */ 
NULL /* No Window Creation data */ 
); 

/* Make the window visible on the screen */ 
ShowWindow (hwnd, nFunsterStil); 

/* Run the message loop. It will run until GetMessage() returns 0 */ 
while (GetMessage (&messages, NULL, 0, 0)) 
{ 
/* Translate virtual-key messages into character messages */ 
TranslateMessage(&messages); 
/* Send message to WindowProcedure */ 
DispatchMessage(&messages); 
} 

/* The program return-value is 0 - The value that PostQuitMessage() gave */ 
return messages.wParam; 
} 

double czl(int n,double x1,double *px,double *py) 
{ 
int i,j; 
double x[10],y[10],t,y1=0; 
for(i=0;i<n;i++,px++,py++) 
{ 
x[i]=*px; 
y[i]=*py; 
} 
for(i=0;i<n;i++) 
{ 
t=1.0; 
for(j=0;j<n;j++) 
{ 
if(i!=j) 
t=t*(x1-x[j])/(x[i]-x[j]); 
} 
y1=y1+t*y[i]; 
} 
return y1; 
} 

/* This function is called by the Windows function DispatchMessage() */ 

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
HDC hdc; 
int n,px,py; 
double i; 
double x,y,*p,*q; 
double u[N]={0,1,2,3,4,5,6,7}; 
double v[N]={0,1,1.414214,1.732051,2,2.236068,2.449490,2.645751}; 
PAINTSTRUCT ps; 
HPEN hP; 
HBRUSH hB; 
switch (message) /* handle the messages */ 
{ 
case WM_PAINT: 
//draw picture 
hP=CreatePen(PS_DASHDOT,1,RGB(0,255,0)); 
hB=CreateHatchBrush(HS_CROSS,RGB(0,255,255)); 

hdc=BeginPaint(hwnd,&ps); 
Rectangle(hdc,0,0,800,600);//矩形 
SetMapMode(hdc,MM_TEXT); 
//COLORREF SetPixel(HDC hdc, int X, int Y, COLORREF crColor); 

SelectObject(hdc,hB); 
SelectObject(hdc,hP); 



MoveToEx(hdc,0,300,NULL); 
LineTo(hdc,800,300);//X轴 
MoveToEx(hdc,200,0,NULL); 
LineTo(hdc,200,600);//Y轴 

for(i=0;i<=400;i++) 
{ 
Sleep(10); 
n=8; 
x=i/100; 
p=u; 
q=v; 
y=czl(n,x,p,q); 
px=x*100+200; 
py=300-y*100; 
SetPixel(hdc,px,py,RGB(0,0,255)); 
} 

EndPaint(hwnd,&ps); 
DeleteObject(hP); 
DeleteObject(hB); 
break; 
case WM_DESTROY: 
PostQuitMessage (0); /* send a WM_QUIT to the message queue */ 
break; 
default: /* for messages that we dont deal with */ 
return DefWindowProc (hwnd, message, wParam, lParam); 
} 

return 0; 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -