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

📄 matlabconsole.cpp

📁 As all of you know, MATLAB is a powerful engineering language. Because of some limitation, some task
💻 CPP
字号:
// MatlabConsole.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

////////////////////////////////////////////////////////////////////////////
//	Copyright : 24 May 2003
//
//	email: a.riazi@misbah3com.com
//
//	This code may be used in compiled form in any way you desire. This
//	file may be redistributed unmodified by any means PROVIDING it is 
//	not sold for profit without the authors written consent, and 
//	providing that this notice and the authors name is included.
//
//	This file is provided 'as is' with no expressed or implied warranty.
//	The author accepts no liability if it causes any damage to your computer.
//
//
//	Description:	Using MATLAB C Math Library
////////////////////////////////////////////////////////////////////////////


//MATLAB library
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmatlb.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmmfile.lib")


int main(int argc, char* argv[])
{
	double dbl1[]={1, 2, 3, 4, 5, 6, 7, 8, 9};
	double dbl2[]={9, 8, 7, 6, 5, 4, 3, 2, 1};
	mxArray *A, *B, *C;

	A=mxCreateDoubleMatrix(3, 3, mxREAL);
	B=mxCreateDoubleMatrix(3, 3, mxREAL);

	//copy an array to matrix A and B
	memcpy(mxGetPr(A), dbl1, 9 * sizeof(double));
	memcpy(mxGetPr(B), dbl2, 9 * sizeof(double));
	
	printf("\nMatrix A:\n");
	mlfPrintMatrix(A);

	printf("\nMatrix B:\n");
	mlfPrintMatrix(B);

	//C=A*B
	C=mlfTimes(A, B);

	printf("\nMatrix C=A*B:\n");
	mlfPrintMatrix(C);
	
	//Magic Matrix
	C=mlfMagic(mlfScalar(4));

	printf("\nMagic Matrix C (order= 4):\n");
	mlfPrintMatrix(C);

	double poly1[]={3, 5, 7};
	double poly2[]={4, 0, 3, -1, 0, 1};
	mxArray *p1, *p2, *p3;

	p1=mxCreateDoubleMatrix(1, 3, mxREAL);
	p2=mxCreateDoubleMatrix(1, 6, mxREAL);

	memcpy(mxGetPr(p1), dbl1, 3 * sizeof(double));
	memcpy(mxGetPr(p2), dbl2, 6 * sizeof(double));

	//Convolution of p1 and p2
	p3=mlfConv(p1, p2);

	printf("\nRoots of polynomial p3\n");
	mlfPrintMatrix(p3);
	printf("is: \n");
	mlfPrintMatrix(mlfRoots(p3));

	mxDestroyArray(A);
	mxDestroyArray(B);
	mxDestroyArray(C);

	mxDestroyArray(p1);
	mxDestroyArray(p2);
	mxDestroyArray(p3);

	return 0;
}

⌨️ 快捷键说明

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