Applying the MATLAB algorithm in. Net

Source: Internet
Author: User
Tags expression sin
In scientific research and engineering application, the algorithm often has to do a lot of mathematical calculation, including matrix operation. These operations are generally difficult to use manually accurate and fast, but the use of computer programming corresponding procedures to do approximate calculation. The current popular use of basic, FORTRAN and C language programming program, not only need to have a deep understanding of the algorithm, but also need to master the language used in the grammar and programming skills. For most scientific workers, it is difficult to have both skills at the same time. Usually, the programming process is also complex, not only consumes human and material resources, but also affects the work process and efficiency. To overcome the above difficulties, the United States Mathwork Company in 1967 launched the "Matrix Laboratory" (abbreviated to MATLAB) software package, and constantly updated and expanded. The latest 6.x version (Windows environment) is an interactive package that is powerful and efficient for scientific and engineering computing. These include: General numerical analysis, matrix operations, digital signal processing, modeling and system control and optimization applications, and set applications and graphics in a user-friendly integration environment. The Matlab language expression form of the problem in this environment is the same as its mathematical form, and it does not need to be programmed according to the traditional method. However, Matlab as a new computer language, want to use freely, give full play to its power, also need to learn it systematically. However, the use of MATLAB programming operations and people to carry out scientific calculation of the idea and expression is completely consistent, so it is not like learning other high-level languages-such as BASIC, Fortran and C and so difficult to master. Practice has proved that you can learn the basic knowledge of MATLAB in a few 10 minutes, you can master it in the use of a few hours. Thus enabling you to perform efficient and creative calculations. Matlab greatly reduces the user's mathematical foundation and computer language knowledge requirements, and programming efficiency and computational efficiency is very high, but also on the computer directly output results and exquisite graphics copy, so it is indeed an efficient research assistants. Since the introduction of the popular United States, the world spread.
MATLAB algorithm is an excellent algorithm, we in the software development process, especially the database development aspect, must carry on the data summary, the statistical analysis, then produces the chart according to the summary data (including the column chart, the pie chart, four cent chart, the radar map and so on), this kind of demand is widespread.
Since the MATLAB algorithm has a powerful computational processing function, so in many software has been used in it, such as a sales forecast, the premise is based on the previous sales data, you can use the MATLAB algorithm to the previous sales Data processing (such as function, Matrix, a series of operations, or using some knowledge of operational research to data processing, and then by the MATLAB algorithm to produce the relevant data of the exquisite graphics output, get a scientific theory based on the program, our management thought into the computer program design, so that the software solution is not a simple computerization tool, But a crystallization of wisdom that synthesizes many disciplines!
Microsoft's. NET development tools, combined with database SQL SERVER, is the best choice to develop database applications! We can use the data in SQL Server in the MATLAB algorithm to process, but also can write their own algorithms to be packaged as COM, in. NET Reference. In the use of the MATLAB algorithm, the graphics output function is often ignored, the following example, is the use of Matlab out of the graphics

First in. NET, referencing the object library of MATLAB (MATLAB application (version 6.5) Type library), the author uses the MATLAB version 6.5, and then add a picture frame on the form PictureBox1, used to display pictures;
A Button1 is used to invoke MATLAB and load graphics.

Code:

Dim Strmatlab As String ' define MATLAB statement string
' Show sine chart
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim MatLab as Object
' Set up MATLAB application
MatLab = CreateObject ("Matlab.application")
' Minimize MATLAB Command Window
Matlab.minimizecommandwindow ()
' MATLAB statement
Strmatlab = "T=2:0.2:4*pi;y=sin (t);p lot (t,y)"
' Execute MATLAB algorithm
Matlab. Execute (Strmatlab)
' Generate a JPG of graphics c:\Test1.jpg
Matlab. Execute ("Print (GCF, '-djpeg ', ' C:\Test1 ')")
' Exit MATLAB, release resources
Matlab. Quit ()
MatLab = Nothing
' Show in picture box
pictureBox1.Image = New Bitmap ("C:\Test1.jpg")
End Sub

' Show pie chart
Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button2.click
Dim matlab as Object
matlab = CreateObject ("Matlab.application")
Strmatlab = "sale=[100];p ie3 (sale,[0 0 1 0 0],{' Company A ', ' Company B ', ' Company C ', ' Company d ', ' Company E '})"
Matlab. Execute (Strmatlab)
Matlab. Execute ("Print (GCF, '-djpeg ', ' C:\Test2 ')")
Matlab. Quit ()
matlab = Nothing
pictureBox1.Image = New Bitmap ("C:\Test2.jpg")
End Sub

' Show three-dimensional spiral chart
Private Sub button3_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button3.click
Dim matlab as Object
matlab = CreateObject ("Matlab.application")
Strmatlab = "t=0:0.2:4*pi;plot3 (sin (t), cos (t), T)"
Matlab. Execute (Strmatlab)
Matlab. Execute ("Print (GCF, '-djpeg ', ' C:\Test3 ')")
Matlab. Quit ()
matlab = Nothing
pictureBox1.Image = New Bitmap ("C:\Test3.jpg")
End Sub

' Show Stereo Wave chart
Private Sub button5_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button5.click
Dim matlab as Object
matlab = CreateObject ("Matlab.application")
Strmatlab = "[x,y,z] = peaks (); Surfc (x,y,z); ColorMap Hsv;axis ([2 4-6 8-10 6])"
Matlab. Execute (Strmatlab)
Matlab. Execute ("Print (GCF, '-djpeg ', ' c:\Test5 ')")
Matlab. Quit ()
matlab = Nothing
pictureBox1.Image = New Bitmap ("C:\Test5.jpg")
End Sub

Private Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
Picturebox1.sizemode = Pictureboxsizemode.stretchimage
End Sub
Summary: In general, we will own the algorithm in MATLAB to generate a DLL, for vb.net call this algorithm, input a set of data, output a series of data, and MATLAB algorithm is relatively simple, a command on the completion of many functions, greatly improve the development efficiency!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.