原创 Labwindows/cvi8.5学习日志(37)----多项式拟合演示仪

2010-7-27 20:33 2910 8 8 分类: 软件与OS


//*****************************************************************************
// Labwindows/cvi8.5  多项式拟合演示仪 
// 自行编写
// szlihongtao         
// 2010-07-27
//*****************************************************************************
#include <analysis.h>
#include <cvirte.h>
#include <userint.h>
#include "lin.h"
//*****************************************************************************
static int panelHandle;
//*****************************************************************************
int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "lin.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 return 0;
}
//*****************************************************************************
int CVICALLBACK func_exit (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_COMMIT:
   QuitUserInterface (0);
   break;
 }
 return 0;
}
//*****************************************************************************
int CVICALLBACK fit (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 double in[6],out[6],best[6],ftemp,intercept[6],my;
 unsigned int k;


 switch (event)
 {
  case EVENT_COMMIT:


   GetCtrlVal (panelHandle, PANEL_IN1, &ftemp);
   in[0]=ftemp;


   GetCtrlVal (panelHandle, PANEL_IN2, &ftemp);
   in[1]=ftemp;


   GetCtrlVal (panelHandle, PANEL_IN3, &ftemp);
   in[2]=ftemp;


   GetCtrlVal (panelHandle, PANEL_IN4, &ftemp);
   in[3]=ftemp;


   GetCtrlVal (panelHandle, PANEL_IN5, &ftemp);
   in[4]=ftemp;
//------------------------------------------------------------------------------
   GetCtrlVal (panelHandle, PANEL_OUT1, &ftemp);
   out[0]=ftemp;


   GetCtrlVal (panelHandle, PANEL_OUT2, &ftemp);
   out[1]=ftemp;


   GetCtrlVal (panelHandle, PANEL_OUT3, &ftemp);
   out[2]=ftemp;


   GetCtrlVal (panelHandle, PANEL_OUT4, &ftemp);
   out[3]=ftemp;


   GetCtrlVal (panelHandle, PANEL_OUT5, &ftemp);
   out[4]=ftemp;
//------------------------------------------------------------------------------
   GetCtrlVal (panelHandle, PANEL_K, &k);


   PolyFit (in, out, 5, k, best, intercept, &my);
//------------------------------------------------------------------------------
   SetCtrlVal (panelHandle, PANEL_BEST1, best[0]);
   SetCtrlVal (panelHandle, PANEL_BEST2, best[1]);
   SetCtrlVal (panelHandle, PANEL_BEST3, best[2]);
   SetCtrlVal (panelHandle, PANEL_BEST4, best[3]);
   SetCtrlVal (panelHandle, PANEL_BEST5, best[4]);


   DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
   PlotXY (panelHandle, PANEL_GRAPH, in, out, 5, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
   PlotXY (panelHandle, PANEL_GRAPH, in, best, 5, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);


   break;
 }
 return 0;
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
8
关闭 站长推荐上一条 /3 下一条