本文目录一览:
- 1、用C语言设计一个简单计算器
- 2、怎么用C语言做二维 三维 动画 窗口的程序?
- 3、KTR POLY联轴器|POLY弹性联轴器的价格|货期哪里可以查?
- 4、matlab调用函数sinint原理
- 5、MMsegmentation教程 6: 自定义运行设定
- 6、Matlab调用IE并根据录入内容然后搜索
用C语言设计一个简单计算器
#includestdio.h
void add(int a,int b,int c)
{
c=a+b;
printf("%d\t",c);
printf("\n");
}
void minus(int a,int b,int c)
{
c=a-b;
printf("%d\t",c);
printf("\n");
}
void multiplication(int a,int b,int c)
{
c=a*b;
printf("%d\t",c);
printf("\n");
}
void div(int a,int b,int c)
{
c=(float)a/(float)b;
printf("%f\t",c);
printf("\n");
}
main()
{
int a,b,c;
char p;
puts("input A:\n");
scanf("%d",a);
puts("input B:\n");
scanf("%d",b);
puts("input operation:\n");
getchar();
p=getchar();
if(p=='+') add(a,b,c);else
if(p=='-') minus(a,b,c);else
if(p=='*') multiplication(a,b,c);else
if(p=='/') div(a,b,c);else
puts("没有注册这个运算符号\n");
}
以上是设计的一个简易计算器。可以进行相应的加减乘除。
简介:
C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点。它由美国贝尔研究所的D.M.Ritchie于1972年推出,1978年后,C语言已先后被移植到大、中、小及微型机上,它可以作为工作系统设计语言,编写系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。它的应用范围广泛,具备很强的数据处理能力,不仅仅是在软件开发上,而且各类科研都需要用到C语言,适于编写系统软件,三维,二维图形和动画,具体应用比如单片机以及嵌入式系统开发。
怎么用C语言做二维 三维 动画 窗口的程序?
我有相关的资料(原版英文书), 但无法传递给你!!! 给你个实例程序:(太长,程序没发完)
/*
GRAPHICS DEMO FOR TURBO C 2.0
Copyright (c) 1987,88 Borland International. All rights reserved.
From the command line, use:
tcc bgidemo graphics.lib
*/
#ifdef __TINY__
#error BGIDEMO will not run in the tiny model.
#endif
#include dos.h
#include math.h
#include conio.h
#include stdio.h
#include stdlib.h
#include stdarg.h
#include graphics.h
#define ESC 0x1b /* Define the escape key */
#define TRUE 1 /* Define some handy constants */
#define FALSE 0 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define ON 1 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
char *Fonts[] = {
"DefaultFont", "TriplexFont", "SmallFont",
"SansSerifFont", "GothicFont"
};
char *LineStyles[] = {
"SolidLn", "DottedLn", "CenterLn", "DashedLn", "UserBitLn"
};
char *FillStyles[] = {
"EmptyFill", "SolidFill", "LineFill", "LtSlashFill",
"SlashFill", "BkSlashFill", "LtBkSlashFill", "HatchFill",
"XHatchFill", "InterleaveFill", "WideDotFill", "CloseDotFill"
};
char *TextDirect[] = {
"HorizDir", "VertDir"
};
char *HorizJust[] = {
"LeftText", "CenterText", "RightText"
};
char *VertJust[] = {
"BottomText", "CenterText", "TopText"
};
struct PTS {
int x, y;
}; /* Structure to hold vertex points */
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int MaxX, MaxY; /* The maximum resolution of the screen */
int MaxColors; /* The maximum # of colors available */
int ErrorCode; /* Reports any graphics errors */
struct palettetype palette; /* Used to read palette info */
/* */
/* Function prototypes */
/* */
void Initialize(void);
void ReportStatus(void);
void TextDump(void);
void Bar3DDemo(void);
void RandomBars(void);
void TextDemo(void);
void ColorDemo(void);
void ArcDemo(void);
void CircleDemo(void);
void PieDemo(void);
void BarDemo(void);
void LineRelDemo(void);
void PutPixelDemo(void);
void PutImageDemo(void);
void LineToDemo(void);
void LineStyleDemo(void);
void CRTModeDemo(void);
void UserLineStyleDemo(void);
void FillStyleDemo(void);
void FillPatternDemo(void);
void PaletteDemo(void);
void PolyDemo(void);
void SayGoodbye(void);
void Pause(void);
void MainWindow(char *header);
void StatusLine(char *msg);
void DrawBorder(void);
void changetextstyle(int font, int direction, int charsize);
int gprintf(int *xloc, int *yloc, char *fmt, ... );
/* */
/* Begin main function */
/* */
int main()
{
Initialize(); /* Set system into Graphics mode */
ReportStatus(); /* Report results of the initialization */
ColorDemo(); /* Begin actual demonstration */
if( GraphDriver==EGA || GraphDriver==EGALO || GraphDriver==VGA )
PaletteDemo();
PutPixelDemo();
PutImageDemo();
Bar3DDemo();
BarDemo();
RandomBars();
ArcDemo();
CircleDemo();
PieDemo();
LineRelDemo();
LineToDemo();
LineStyleDemo();
UserLineStyleDemo();
TextDump();
TextDemo();
CRTModeDemo();
FillStyleDemo();
FillPatternDemo();
PolyDemo();
SayGoodbye(); /* Give user the closing screen */
closegraph(); /* Return the system to text mode */
return(0);
}
/* */
/* INITIALIZE: Initializes the graphics system and reports */
/* any errors which occured. */
/* */
void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/
GraphDriver = DETECT; /* Request auto-detection */
initgraph( GraphDriver, GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
getpalette( palette ); /* Read the palette from board */
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/
MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */
getaspectratio( xasp, yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */
}
/* */
/* REPORTSTATUS: Report the current configuration of the system */
/* after the auto-detect initialization. */
/* */
void ReportStatus(void)
{
struct viewporttype viewinfo; /* Params for inquiry procedures*/
struct linesettingstype lineinfo;
struct fillsettingstype fillinfo;
struct textsettingstype textinfo;
struct palettetype palette;
char *driver, *mode; /* Strings for driver and mode */
int x, y;
getviewsettings( viewinfo );
getlinesettings( lineinfo );
getfillsettings( fillinfo );
gettextsettings( textinfo );
getpalette( palette );
x = 10;
y = 4;
MainWindow( "Status report after InitGraph" );
settextjustify( LEFT_TEXT, TOP_TEXT );
driver = getdrivername();
mode = getmodename(GraphMode); /* get current setting */
gprintf( x, y, "Graphics device : %-20s (%d)", driver, GraphDriver );
gprintf( x, y, "Graphics mode : %-20s (%d)", mode, GraphMode );
gprintf( x, y, "Screen resolution : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
gprintf( x, y, "Current view port : ( %d, %d, %d, %d )",
viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
gprintf( x, y, "Clipping : %s", viewinfo.clip ? "ON" : "OFF" );
gprintf( x, y, "Current position : ( %d, %d )", getx(), gety() );
gprintf( x, y, "Colors available : %d", MaxColors );
gprintf( x, y, "Current color : %d", getcolor() );
gprintf( x, y, "Line style : %s", LineStyles[ lineinfo.linestyle ] );
gprintf( x, y, "Line thickness : %d", lineinfo.thickness );
gprintf( x, y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
gprintf( x, y, "Current fill color : %d", fillinfo.color );
gprintf( x, y, "Current font : %s", Fonts[ textinfo.font ] );
gprintf( x, y, "Text direction : %s", TextDirect[ textinfo.direction ] );
gprintf( x, y, "Character size : %d", textinfo.charsize );
gprintf( x, y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
gprintf( x, y, "Vertical justify : %s", VertJust[ textinfo.vert ] );
Pause(); /* Pause for user to read screen*/
}
/* */
/* TEXTDUMP: Display the all the characters in each of the */
/* available fonts. */
/* */
void TextDump()
{
static int CGASizes[] = {
1, 3, 7, 3, 3 };
static int NormSizes[] = {
1, 4, 7, 4, 4 };
char buffer[80];
int font, ch, wwidth, lwidth, size;
struct viewporttype vp;
for( font=0 ; font5 ; ++font ){ /* For each available font */
sprintf( buffer, "%s Character Set", Fonts[font] );
MainWindow( buffer ); /* Display fontname as banner */
getviewsettings( vp ); /* read current viewport */
settextjustify( LEFT_TEXT, TOP_TEXT );
moveto( 2, 3 );
buffer[1] = '\0'; /* Terminate string */
wwidth = vp.right - vp.left; /* Determine the window width */
lwidth = textwidth( "H" ); /* Get average letter width */
if( font == DEFAULT_FONT ){
changetextstyle( font, HORIZ_DIR, 1 );
ch = 0;
while( ch 256 ){ /* For each possible character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (getx() + lwidth) wwidth )
moveto( 2, gety() + textheight("H") + 3 );
++ch; /* Goto the next character */
}
}
else{
size = (MaxY 200) ? CGASizes[font] : NormSizes[font];
changetextstyle( font, HORIZ_DIR, size );
ch = '!'; /* Begin at 1st printable */
while( ch 127 ){ /* For each printable character */
buffer[0] = ch; /* Put character into a string */
outtext( buffer ); /* send string to screen */
if( (lwidth+getx()) wwidth ) /* Are we still in window? */
moveto( 2, gety()+textheight("H")+3 );
++ch; /* Goto the next character */
}
}
Pause(); /* Pause until user acks */
} /* End of FONT loop */
}
/* */
/* BAR3DDEMO: Display a 3-D bar chart on the screen. */
/* */
void Bar3DDemo(void)
{
static int barheight[] = {
1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3 };
struct viewporttype vp;
int xstep, ystep;
int i, j, h, color, bheight;
char buffer[10];
MainWindow( "Bar 3-D / Rectangle Demonstration" );
h = 3 * textheight( "H" );
getviewsettings( vp );
settextjustify( CENTER_TEXT, TOP_TEXT );
changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
outtextxy( MaxX/2, 6, "These are 3-D Bars" );
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
getviewsettings( vp );
line( h, h, h, vp.bottom-vp.top-h );
line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
xstep = ((vp.right-vp.left) - (2*h)) / 10;
ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
j = (vp.bottom-vp.top) - h;
settextjustify( CENTER_TEXT, CENTER_TEXT );
for( i=0 ; i6 ; ++i ){
line( h/2, j, h, j );
itoa( i, buffer, 10 );
outtextxy( 0, j, buffer );
j -= ystep;
}
j = h;
settextjustify( CENTER_TEXT, TOP_TEXT );
for( i=0 ; i11 ; ++i ){
color = random( MaxColors );
setfillstyle( i+1, color );
line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
itoa( i, buffer, 10 );
outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
if( i != 10 ){
bheight = (vp.bottom-vp.top) - h - 1;
bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight, 15, 1 );
}
j += xstep;
}
Pause(); /* Pause for user's response */
}
/* */
/* RANDOMBARS: Display random bars */
/* */
void RandomBars(void)
{
int color;
MainWindow( "Random Bars" );
StatusLine( "Esc aborts or press a key..." ); /* Put msg at bottom of screen */
while( !kbhit() ){ /* Until user enters a key... */
color = random( MaxColors-1 )+1;
setcolor( color );
setfillstyle( random(11)+1, color );
bar3d( random( getmaxx() ), random( getmaxy() ),
random( getmaxx() ), random( getmaxy() ), 0, OFF);
}
Pause(); /* Pause for user's response */
}
/* */
/* TEXTDEMO: Show each font in several sizes to the user. */
/* */
void TextDemo(void)
{
int charsize[] = {
1, 3, 7, 3, 4 };
int font, size;
int h, x, y, i;
struct viewporttype vp;
char buffer[80];
for( font=0 ; font5 ; ++font ){ /* For each of the four fonts */
sprintf( buffer, "%s Demonstration", Fonts[font] );
MainWindow( buffer );
getviewsettings( vp );
changetextstyle( font, VERT_DIR, charsize[font] );
settextjustify( CENTER_TEXT, BOTTOM_TEXT );
outtextxy( 2*textwidth("M"), vp.bottom - 2*textheight("M"), "Vertical" );
changetextstyle( font, HORIZ_DIR, charsize[font] );
settextjustify( LEFT_TEXT, TOP_TEXT );
outtextxy( 2*textwidth("M"), 2, "Horizontal" );
settextjustify( CENTER_TEXT, CENTER_TEXT );
x = (vp.right - vp.left) / 2;
y = textheight( "H" );
for( i=1 ; i5 ; ++i ){ /* For each of the sizes */
size = (font == SMALL_FONT) ? i+3 : i;
changetextstyle( font, HORIZ_DIR, size );
h = textheight( "H" );
y += h;
sprintf( buffer, "Size %d", size );
outtextxy( x, y, buffer );
}
if( font != DEFAULT_FONT ){ /* Show user declared font size */
y += h / 2; /* Move down the screen */
settextjustify( CENTER_TEXT, TOP_TEXT );
setusercharsize( 5, 6, 3, 2 );
changetextstyle( font, HORIZ_DIR, USER_CHAR_SIZE );
outtextxy( (vp.right-vp.left)/2, y, "User Defined Size" );
}
Pause(); /* Pause to let user look */
} /* End of FONT loop */
}
/* */
/* COLORDEMO: Display the current color palette on the screen. */
/* */
void ColorDemo(void)
{
struct viewporttype vp;
int color, height, width;
int x, y, i, j;
char cnum[5];
MainWindow( "Color Demonstration" ); /* Show demonstration name */
color = 1;
getviewsettings( vp ); /* Get the current window size */
width = 2 * ( (vp.right+1) / 16 ); /* Get box dimensions */
height = 2 * ( (vp.bottom-10) / 10 );
x = width / 2;
y = height / 2; /* Leave 1/2 box border */
for( j=0 ; j3 ; ++j ){ /* Row loop */
for( i=0 ; i5 ; ++i ){ /* Column loop */
setfillstyle(SOLID_FILL, color); /* Set to solid fill in color */
setcolor( color ); /* Set the same border color */
bar( x, y, x+width, y+height ); /* Draw the rectangle */
rectangle( x, y, x+width, y+height ); /* outline the rectangle */
if( color == BLACK ){ /* If box was black... */
setcolor( WHITE ); /* Set drawing color to white */
rectangle( x, y, x+width, y+height ); /* Outline black in white*/
}
itoa( color, cnum, 10 ); /* Convert # to ASCII */
outtextxy( x+(width/2), y+height+4, cnum ); /* Show color # */
color = ++color % MaxColors; /* Advance to the next color */
x += (width / 2) * 3; /* move the column base */
} /* End of Column loop */
y += (height / 2) * 3; /* move the row base */
x = width / 2; /* reset column base */
} /* End of Row loop */
Pause(); /* Pause for user's response */
}
/* */
/* ARCDEMO: Display a random pattern of arcs on the screen */
/* until the user says enough. */
/* */
void ArcDemo(void)
{
int mradius; /* Maximum radius allowed */
int eangle; /* Random end angle of Arc */
struct arccoordstype ai; /* Used to read Arc Cord info */
MainWindow( "Arc Demonstration" );
StatusLine( "ESC Aborts - Press a Key to stop" );
mradius = MaxY / 10; /* Determine the maximum radius */
while( !kbhit() ){ /* Repeat until a key is hit */
setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
eangle = random( 358 ) + 1; /* Select an end angle */
arc( random(MaxX), random(MaxY), random(eangle), eangle, mradius );
getarccoords( ai ); /* Read Cord data */
line( ai.x, ai.y, ai.xstart, ai.ystart ); /* line from start to center */
line( ai.x, ai.y, ai.xend, ai.yend ); /* line from end to center */
} /* End of WHILE not KBHIT */
Pause(); /* Wait for user's response */
}
KTR POLY联轴器|POLY弹性联轴器的价格|货期哪里可以查?
济南埃姆依机电设备有限责任公司是一家多年从事机电一体化设备销售的专业性公司
公司成立伊始,就把“为客户提供一流的传动机械设备”作为经营理念;把“客户是上帝,一切为用户着想”作为服务理念。全心全意为广大用户服务,经过全体员工的不懈努力,公司业绩蒸蒸日上。现在我公司已成为多个国内外知名品牌在山东的核心代理商,我们代理的主要产品是:汉森减速机系列、、电机系列以及KTR联轴器系列,各个产品的价格优势都非常明显。
主要经营产品:
KTR联轴器,德国EK2联轴器,EKL联轴器
纽卡特(Neugart)行星减速机
伦茨伺服系统
R+W联轴器
汉森减速机
三木联轴器
等
电话:
0531-88014512
传真:
0531-88014557
邮箱:
jn_me@126.com
地址:山东省济南市花园路45号
网址:
24小时服务:
(0)13465310635
matlab调用函数sinint原理
CameraPositionMode:位置取值模式
CameraTarget:目标[x,y,z]
CameraTargetMode:目标模式
CameraUpVector:正位向量
CameraUpVectorMode:正位向量模式
CameraViewAngle:视角【0 180】
CameraViewAngleMode:视角取值模式
Projection:投影方式
6.6 图形输出控制
NextPlot属性值:new、add、replace、 replacechildren
通过hold on和hold off可以设定图形窗口对象和轴对象的属性设置为add和replace。
7 程序设计
7.1 M文件
M文件就是一系列相关代码组成的一个扩展名为.m的文件。分为脚本文件和函数文件两类。
脚本文件不自带参数;
函数文件以function…开始
函数工作区间:Function workspace
M文件结构:函数声明行、H1行、帮助文本、编写和修改注释、函数体
P-码文件:为M文件生成的内部伪代码
P-码文件的预生成函数为Pcode,格式:pcode Func_name当前路径
Pcode Func_name-inplace M文件目录
对P-码文件的操作:
Inmem:列出所有内存中P-码文件名
Clear Func_name:清楚某个p-码文件
Clear function:清楚所有p-码文件
7.2 函数
分为M-函数文件和匿名函数
一个M文件只能有1个主函数,多个子函数
主函数还分为:私用函数和重载函数
嵌套函数:多平行和多层嵌套
7.3 变量
变量名区分大小写;
最多包含63个字符;
必须以字母开始起名,后可为字母、下划线;
不允许出现标点符号。
17个系统关键字:break、case、catch、continue、else、elseif、end、for、function、globle、if、otherwise、persistent、return、switch、try、while
可在命令窗口输入iskeyword显示。
特殊变量:ans,beep,pi,eps,inf,NaN(nan,i(j),nargin(输入个数),nargout(输出个数),realmin,realmax,bitmax,varargin(可变的函数输入参数个数),varargout
分为局部变量、全局变量(globle)、永久变量(persistent)
Inputname(n):第n个输入变量的调用名
7.4 程序结构
分为顺序结构、循环结构(for或while)和分支结构(if或switch)
7.5 程序控制语句
结束循环:continue、break、return
Continue和break:结束本次循环
Warning:错误警告语句
Error和errordlg(显示对话框)
Try…catch:try中有错是执行catch语句
Input和keyboard:输入控制语句
8 程序调试、优化和出错处理
8.1 调试
调试(debug):去除bug
Bug:语法错误、逻辑错误、异常
Debug函数:
Dbstop:设置断点
Dbclear:清除断点
Dbcout:重新执行
Dbdown/dbup:变更当前工作空间
Dbmex:MEX文件调试
Dbstack:列出函数调用关系
Dbstatus:列出所有断点
Dbstep:单步或多步执行
Dbtype:列印M文件
Dbquit:退出调试模式
Debug辅助函数:
Echo:在命令窗口显示当前执行代码
Disp:显示变量
Sprintf/fprintf:指定格式显示文本
Whos:列出工作空间中所有变量
Size:显示变量的大小
Keyboard:中断程序执行,等待输入
Return:结束函数执行
Warning:引发、显示指定的警告
Error:引发、显示指定的错误
Laster:返回最近产生的错误消息
Lasterror:错误消息及相关信息
Lastwarn:返回最近产生的警告
8.2 性能优化
码表:tic——toc时间测试
效率优化技术:
代码向量化
预分配足够大的数组
对不可避免且耗时很大的循环尝试在MEX文件内实现
尽量避免更改变量的数据类型或维数
尽量避免实数和复数之间的相互赋值
尽量采用实数运算
合理使用逻辑运算
尽量采用函数而不是脚本文件
尽量使用load、save而不是IO函数
内存优化技术:whos,clear,save,load
预分配足够大的数组
尽量在函数开始时创建变量
利用repmat增加数组的空间大小
对大部分数据为0的矩阵变为稀疏矩阵
若要保存大量数据采用数组构架而非构架数组
及时地清除占用内存很大的临时变量
尽量地重用内存,而非开辟新内存
8.3 出错处理
Try…catch查询语句
9 MATLAB符号计算
9.1 符号对象的创建
符号变量由sym和syms两条语句生成
Findsym(expression)找出表达式中变量
Findsym(espression,N)离x最近的N个
符号矩阵:S=sym(S)
符号函数:符号表达式、M文件
三类运算操作:
Numberic:数值运算
Rational:Maple符号运算
VPA:Maple精度可变运算
数值转换函数:double,int8/16/32/64,
Uint8/16/32/64
Vpa指令:给出结果
Digits:获得当前精度或变为其他精度
9.2 符号表达式操作
符号表达式指令:
Collect(ex)/collect(ex,x):合并同幂项/含指定x的同幂项
Expand(ex):按多项式展开
Factor(ex)/factor(n):因式/质数分解
Horner(ex):变为嵌套形式
[n,d]=numden(ex):变为有理分式形式,提取最小分母因子d,相应分子公因子n
Simplify(ex):Maple规则化简
Simple(ex)/ [exp,how]=simple(ex):化为最简/给出最简exp,主要化简步骤how
表达式替换:subs(手动),subexpr(自动)
Subs:
R=subs(S)替换所有工作区间符号变量
R=subs(S,new)用new替换S中默认变
R=subs(S,old,new)用new替换old
Subexpr:
[exp,sigma]=subexpr(ex,sigma)或者
[exp,sigma]=subexpr(ex,’sigma’)
9.3 符号函数操作
函数复合:compose
求反函数:finverse
Cosine积分函数:cosint
冲激函数:dirac
阶跃函数:heaviside
超几何函数:hypergeom
Lambert函数:lambertw
Sine积分函数:sinint
黎曼函数:zeta
傅里叶变换:fourier
逆傅里叶变换:ifourier
逆拉普拉斯变换:ilaplace
逆Z变换:iztrans
Laplace变换:laplace
Z变换:ztrans
9.4 符号矩阵操作
代数运算:
,-,*,./,.\,^,\,/,.*,.^,’,.’
逻辑运算:(仅有)==,~=
行列式:det计算
矩阵的逆:inv
矩阵的秩:rank
特征分解:solve(poly(A))或eig
SVD分解:svd
9.5 符号微积分
极限:limit
左右极限在括号写明(right/left),且加引号
微分:diff(S,n,’v’)后两者和x可省略
S为因变量,v为微分变量,n为阶数
多元向量函数矩阵:jacobian(G,x)
积分:int
不定积分:int(S,x),x可省略
定积分:int(S,x,a,b),x可省略
级数展开:taylor自变量v
Taylor(f):f的5阶马克劳林级数逼近
Taylor(f,n,v):f的n-1马克劳林
Taylor(f,m1,m2):f在m2的m1-1阶
Taylor(f,n,v,a):x=a处n-1阶
级数求和:symsum
9.6 符号方程求解
一般代数方程:solve
线性代数方程组:通解null(A),特解由A\B
常微分方程:dsolve
10 数据分析
10.1 数据排序分析
最大(小)值:max/min
中位数:median(A)
分位数:quantile(X,p)
排序:sort、sortrows
升序ascend,降序descend,加引号
Sortrows行为整体排序
10.2 数据求和(积)、差分
求和:sum
对矩阵sum(A)列和,sum(A,2)行和
求积:prod
求累计和、积:cumsum、cumprod
差分:diff(X,N),N为阶数
10.3 均值和方差分析
均值:mean(A,dim)
标准差:std(A,flag,dim)
dim维数可省略
flag为0和1时得到Ⅰ和Ⅱ型标准差
10.4 数据预处理
缺失数据(NaN):用isnan函数判断并去除
异常数据:与平均值的偏差大于3倍标准差
10.5 统计分析
显示概率分布:disttool
随机数生成:所有函数基于rand,randn,且以rnd结尾
数据直方图分析:hist(X,M),M正整数标量,且可有返回值,用bar(x,n)作图
描述数据中心函数:
geomean几何均值
harmmean调和均值
mean:算术均值
median:中位数
trimmea修正均值(除去部分最大最小)
描述数据散步程度:
iqr:四分位差,即25%和75%
mad:绝对值标准偏差
range:跨度,最小最大之差
std:标准差
kurtosis:峭度
11 矩阵分析
11.1 矩阵分析的应用背景
高效、简洁、安全
11.2 矩阵特征量
det(行列式值),inv(逆),rank(秩)
范数:norm(A,opt) ,opt默认2
矩阵opt可取1,2,inf,’fro’
向量opt可取1=p∞,2,inf,-inf
条件数:cond(A,opt) opt为范数,省为2
接近1矩阵为良性,远大于1为病态,接近无穷是叫奇异矩阵
超定方程、恰定方程、欠定方程
特征值:eig或eigs
D=eig(A)返回值D的N个特征值组成的向量
[V,D]=eig(A)返回值D的N阶对角矩阵,V为N*N矩阵
11.3 矩阵分解
EVD分解:eig,eigs
MMsegmentation教程 6: 自定义运行设定
我们已经支持 PyTorch 自带的所有优化器,唯一需要修改的地方是在配置文件里的 optimizer 域里面。
例如,如果您想使用 ADAM (注意如下操作可能会让模型表现下降),可以使用如下修改:
为了修改模型的学习率,使用者仅需要修改配置文件里 optimizer 的 lr 即可。
使用者可以参照 PyTorch 的 API 文档
直接设置参数。
一个自定义的优化器可以按照如下去定义:
假如您想增加一个叫做 MyOptimizer 的优化器,它的参数分别有 a , b , 和 c 。
您需要创建一个叫 mmseg/core/optimizer 的新文件夹。
然后再在文件,即 mmseg/core/optimizer/my_optimizer.py 里面去实现这个新优化器:
为了让上述定义的模块被框架发现,首先这个模块应该被导入到主命名空间 (main namespace) 里。
有两种方式可以实现它。
mmseg.core.optimizer.my_optimizer 模块将会在程序运行的开始被导入,并且 MyOptimizer 类将会自动注册。
需要注意只有包含 MyOptimizer 类的包 (package) 应当被导入。
而 mmseg.core.optimizer.my_optimizer.MyOptimizer 不能 被直接导入。
事实上,使用者完全可以用另一个按这样导入方法的文件夹结构,只要模块的根路径已经被添加到 PYTHONPATH 里面。
之后您可以在配置文件的 optimizer 域里面使用 MyOptimizer
在配置文件里,优化器被定义在 optimizer 域里,如下所示:
为了使用您自己的优化器,这个域可以被改成:
有些模型可能需要在优化器里有一些特别参数的设置,例如 批归一化层 (BatchNorm layers) 的 权重衰减 (weight decay)。
使用者可以通过自定义优化器的构造器去微调这些细粒度参数。
默认的优化器构造器的实现可以参照 这里 ,它也可以被用作新的优化器构造器的模板。
优化器没有实现的一些技巧应该通过优化器构造器 (optimizer constructor) 或者钩子 (hook) 去实现,如设置基于参数的学习率 (parameter-wise learning rates)。我们列出一些常见的设置,它们可以稳定或加速模型的训练。
如果您有更多的设置,欢迎在 PR 和 issue 里面提交。
我们根据默认的训练迭代步数 40k/80k 来设置学习率,这在 MMCV 里叫做 PolyLrUpdaterHook 。
我们也支持许多其他的学习率计划表: 这里 ,例如 CosineAnnealing 和 Poly 计划表。下面是一些例子:
工作流是一个专门定义运行顺序和轮数 (running order and epochs) 的列表 (phase, epochs)。
默认情况下它设置成:
意思是训练是跑 1 个 epoch。有时候使用者可能想检查模型在验证集上的一些指标(如 损失 loss,精确性 accuracy),我们可以这样设置工作流:
于是 1 个 epoch 训练,1 个 epoch 验证将交替运行。
注意 :
如果钩子已经在 MMCV 里被实现,如下所示,您可以直接修改配置文件来使用钩子:
以下的常用的钩子没有被 custom_hooks 注册:
在这些钩子里,只有 logger hook 有 VERY_LOW 优先级,其他的优先级都是 NORMAL 。
上述提及的教程已经包括了如何修改 optimizer_config , momentum_config 和 lr_config 。
这里我们展示我们如何处理 log_config , checkpoint_config 和 evaluation 。
MMCV runner 将使用 checkpoint_config 去初始化 CheckpointHook .
使用者可以设置 max_keep_ckpts 来仅保存一小部分检查点或者通过 save_optimizer 来决定是否保存优化器的状态字典 (state dict of optimizer)。 更多使用参数的细节请参考 这里 。
log_config 包裹了许多日志钩 (logger hooks) 而且能去设置间隔 (intervals)。现在 MMCV 支持 WandbLoggerHook , MlflowLoggerHook 和 TensorboardLoggerHook 。
详细的使用请参照 文档 。
evaluation 的配置文件将被用来初始化 EvalHook 。
除了 interval 键,其他的像 metric 这样的参数将被传递给 dataset.evaluate() 。
Matlab调用IE并根据录入内容然后搜索
function RandDisplayJiong
axis off; %隐去坐标轴
set(gcf,'menubar','none','toolbar','none');%不显示当前figure 菜单栏和工具栏
for k = 1:100 %循环100次
%每次在(rand,rand)这个随机的位置,以20到50之间随机分布的一个数为字体大小,隶书的形式,
%随机生成RGB颜色,并随机旋转一定角度来显示“囧”
h = text(rand,rand,...
['\fontsize{',num2str(unifrnd(20,50)),'}\fontname {隶书} 囧'],...
'color',rand(1,3),'Rotation',360*rand);
pause(0.2); %每显示完一次暂停0.2秒
end
function T = cat_in_holl(n)
T = zeros(1,n);
for k = 1:n
c = unidrnd(3,1);
while c ~= 1
if c == 2
T(k) = T(k)+4;
else
T(k) = T(k)+6;
end
c = unidrnd(3,1);
end
T(k) = T(k)+2;
end
function example2_3_6slow
A = unidrnd(100,1000000,7);%随机生成1000000*7的A矩阵,A的元素属于1到100的整数
B = zeros(1000000,3);
for m = 1:1000000
a = A(m,:);
b = [4 6 8];
for ii = 1:3
dd = a(a==b(ii));%dd:a中等于b(ii)的元素
if isempty(dd)==0 %dd不为空
b(ii)=0;
end
end
B(m,:)=b;
end
function [m,n,TT]=plot3dnmT(N,L)
%N:inf的近似,L:[0,2]区间的剖分个数
C=zeros(N,1);%nested-function:Tmn=calcT(mm,nn)中用来存储计算结果
m=linspace(0,2,L);
[m,n]=meshgrid(m,m);
TT=zeros(size(n));%和网格数据m,n对应的计算出来的T(m,n)网格数据
for ii=1:L
for jj=1:L
TT(ii,jj)=calcT(m(ii,jj),n(ii,jj));
end
end
%=====计算T(m,n)的nest-function
function Tmn=calcT(mm,nn)
for N1=1:N
C(N1)=(mm^N1/gamma(N1+1))*sum( nn.^(0:N1-1)./gamma(1:N1) );
Tmn=1.0-exp(-mm-nn)*sum(C);
end
end
mesh(n,m,TT);
end
function [mx,minf]=randwalk(f,x,lamda,epsilon,N)
%随机行走法求函数的极小值。输入f为所求函数的句柄,
%x为初始值。lamda为步长。epsilon为控制lamda的减小的阈值,即lamda减小到epsilon时
%迭代停止。
%N为为了产生较好点的迭代控制次数。
%函数返回值mx为n次试验得到的最优解,minf为响应的最优值。
f1 = f(x(1),x(2));
while(lamda=epsilon)
k = 1;
while(k=N)
u = unifrnd(-1,1,1,2);
x1 = x+lamda*(u/norm(u));
f11 = f(x1(1),x1(2));
if f11f1
f1 = f11;
x = x1;
k = 1;
else
k = k+1;
end
end
lamda = lamda/2;
end
mx = x1;
minf = f1;
function triangle_table
fig = figure('defaultuicontrolunits','normalized','name','triangle_table',...
'numbertitle','off','menubar','none');
ah = axes('Pos',[.1 .2 .75 .75],'Visible','off');
slider_h = uicontrol('style','slider','units','normalized','pos',...
[0.1,0.05,0.75,0.05],'sliderstep',[1/6,0.05],'callback',@change_color);
hold on
for k = 0:6
plot(0:6-k,(6-k)*ones(1,(7-k)),'k');
plot(k*ones(1,(7-k)),k:6,'k');
end
plot([0,6],[0,6],'k');
hold off;
for x = 1:5
for y = 1:x
text(y-0.5,x+0.5,num2str(x),'color','k','tag','数字');
end
end
for k = 0:5
text(k+0.1,k+0.5,[num2str(k),'.5'],'tag','数字');
end
%====slider's callback function(nested function)======
function change_color(hObject,eventdata)
v = round(6*get(slider_h,'value'));
num_h = findobj('tag','数字');
num_pos = get(num_h,'pos');
red_num_logic = cellfun(@(x) (x(1)=vx(2)=v),num_pos);
set(num_h(red_num_logic),'color','r');
set(num_h(~red_num_logic),'color','k');
end
end
function DuckLakeSegmentation
%导入图像文件引导对话框
[filename,pathname,flag] = uigetfile('*.jpg','请导入图像文件');
Duck = imread([pathname,filename]);
LakeTrainData = [52 74 87;76 117 150;19 48 62;35 64 82;46 58 36;...
50 57 23;110 127 135;156 173 189;246 242 232;...
166 174 151];%从图上选取的几个位于湖面区域的有代表的点的RGB值
%从图上选取的几个位于鸭子区域的有代表的点的RGB值
DuckTrainData = [211 192 107;202 193 164;32 25 0;213 201 151;115 75 16;...
101 70 0;169 131 22;150 133 87];
%属于湖的点为0,鸭子为1
group = [zeros(size(LakeTrainData,1),1);ones(size(DuckTrainData,1),1)];
LakeDuckSVM = svmtrain([LakeTrainData;DuckTrainData],group,...
'Kernel_Function','polynomial','Polyorder',2);%训练得到支持向量分类机
[m,n,k] = size(Duck);
Duck1 = double(reshape(Duck, m*n, k));%将数组Duck转成m*n行,3列的双精度矩阵
%根据训练得到的支持向量机对整个图像的像素点分类
IndDuck = svmclassify(LakeDuckSVM,Duck1);
IndLake = ~IndDuck;%属于湖的点的逻辑数组
result = reshape([IndLake, IndLake, IndLake],[m,n,k]);%和图片的维数相对应
Duck2 = Duck;
Duck2(result) = 0;
figure
imshow(Duck2)
function example12_1_3
%定时器的TimerFun,供TimerA,TimerB,TimerC共用
function TimerFun(object,event)
t = clock; %函数刚开始执行时间点
pause(1);%函数执行了1秒钟
et = etime(t,get(object,'userdata'));%函数开始运行和上次函数开始运行时间间隔
disp(['本次函数开始执行距上次函数开始执行时间为:',num2str(et),' S!'])
set(object,'userdata',t);%记录本次函数开始运行时间
end
%定义定时器TimerA, 'executionmode'设为'fixedSpacing'
TimerA = timer('StartFcn','disp(''定时器A开始:'')','ErrorFcn',...
'disp(''A发生错误'')','StartDelay',0.5,'TimerFcn',@TimerFun,'stopfcn',...
'disp(''定时器A停止!'')','executionmode','fixedSpacing','period',0.5,...
'TasksToExecute',3);
%定义定时器TimerB, 'executionmode'设为'fixedDelay'
TimerB = timer('StartFcn','disp(''定时器B开始:'')','ErrorFcn',...
'disp(''B发生错误'')','StartDelay',0.5,'TimerFcn',@TimerFun,'stopfcn',...
'disp(''定时器B停止!'')','executionmode','fixedDelay','period',0.5,...
'TasksToExecute',3);
%定义定时器TimerC, 'executionmode'设为'fixedRate'
TimerC = timer('StartFcn','disp(''定时器C开始:'')','ErrorFcn',...
'disp(''C发生错误'')','StartDelay',0.5,'TimerFcn',@TimerFun,'stopfcn',...
'disp(''定时器C停止!'')','executionmode','fixedRate','period',0.5,...
'TasksToExecute',3);
%运行定时器A
set(TimerA,'userdata',clock);
start(TimerA);
wait(TimerA);
%运行定时器B
set(TimerB,'userdata',clock);
start(TimerB);
wait(TimerB);
%运行定时器C
set(TimerC,'userdata',clock);
start(TimerC);
wait(TimerC);
end