Simple Application of Visual scientific computing MATLAB Language

Source: Internet
Author: User

Abstract:MATLAB is a new advanced language widely used in engineering computing and numerical analysis. It has experienced more than 10 years of development and competition since it was introduced to the market by Mathworks in 1984, it is now internationally recognized as the best engineering application development environment. MATLAB has powerful functions, is easy to learn, and has high programming efficiency. It is very popular among scientific and technological workers. It is also useful in my professional studies. Through the process of learning MATLAB, this article links the problems encountered in my major with the Application of MATLAB, and uses MATLAB to solve some practical problems. It shows that MATLAB is widely used. Keywords:MATLAB, application, professional learning 0. IntroductionMATLAB is known as a tool on the shoulders of giants ". Because the idea and Expression of Matlab programming operations are completely consistent with that of scientific computing, it is not as difficult to master as learning other advanced languages, such as basic, C, and C ++, programming with Matlab is like listing formulas and solving problems on the computing paper, therefore, it is also known as computational paper-type scientific algorithm language. Generally, it is used for numerical analysis, matrix calculation, digital signal processing, modeling, system control, optimization, and other applications, combine applications and graphics in an easy-to-use integrated environment. In this environment, you only need to list the mathematical expressions for the problem to be solved, and the results are displayed in numerical or graphical form. These advantages of MATLAB make him widely used in various fields. The following describes how to use it in my professional learning process. 1. Solving Non-Linear EquationsIn the learning process, we often encounter the problem of solving non-linear equations. For example, if there is a question, the final solution is a non-linear equation: X2 + X-E (1 + x) -0.5 = 0 problems like this I used to calculate through two methods: the first method is the trial difference method, which can be used when the equation is simple, however, when the equation is very complex, the computation will become quite cumbersome. The other is that programming is done by means of a binary or Newton iteration, but this usually requires a lot of code. Now we can use MATLAB to easily solve this problem, as long as the following line of code is enough. Fzero ('x ^ 2 + X-exp (1 + x/0.5)-100', 0) ans = 1.3623 2. PlottingHere is an example of how to calculate the number of theoretical plates in a rectification column by graphic method. The Phase Equilibrium parameters of materials are known, and the operating line equations of the distillation and distillation sections of the distillation column are required. The number of theoretical trays required must be determined by Graphic solutions. If such a question is used for programming, it will be time-consuming and time-consuming. Below is a piece of program I compiled using C # (only the main part, the source code is more than this ). Protected override void onpaint (painteventargs e) {base. onpaint (E); graphics G = E. graphics; pen p1 = new pen (color. black, 2); pen P2 = new pen (color. black, 1); drawrec (G, P1); drawmidline (G, P2); drawpinghengline (G, P2); drawjldandtldoperationline (G, P2); drawkedu (G, P2 ); drawjldandtldoperationline (G, P2); drawtaban (G, P1); p1.dispose (); p2.dispose (); G. dispose ();} Private Static void drawgrid (Graphics g, pen P2) {for (INT I = 1; I <100; I ++) g. drawline (P2, 50 + I * 5, 50, 50 + I * 5,550); For (INT I = 1; I <100; I ++) g. drawline (P2, 50, 50 + I * 5,550, 50 + I * 5);} Private Static void drawkedu (Graphics g, pen p) {for (INT I = 1; I <10; I ++) g. drawline (p, 50 + I * 50, 50, 50 + I * 50, 55); For (INT I = 1; I <10; I ++) g. drawline (p, 50, 50 + I * 50, 55, 50 + I * 50);} Private Static void drawjldandtldoperationline (Graphics g, pen p) {G. drawline (p, 490,490,225,314); G. drawline (p, 225,314, 72, 72);} Private Static void drawtaban (Graphics g, pen p) {int X2 = 0, y2 = 0; int Y1 = 490; int X1 = F3 (Y1); G. drawline (p, Y1, Y1, X1, Y1); While (x1> 225) {y2 = F1 (X1); x2 = F3 (Y1); G. drawline (p, X1, Y1, X2, Y1); G. drawline (p, X2, Y1, X2, Y2); X1 = x2; Y1 = Y2;} while (x1> 72) {y2 = F2 (X1 ); x2 = F3 (Y1); G. drawline (p, X1, Y1, X2, Y1); G. drawline (p, X2, Y1, X2, Y2); X1 = x2; Y1 = Y2;} G. drawline (p, X2, Y2, X2, X2);} private void drawpinghengline (Graphics g, pen p) {for (INT I = 1; I <500; I ++) {int xi = (INT) pinghengxian (I); G. drawline (p, XI, I + 50, Xi + 1, I + 51) ;}} Private Static void drawmidline (Graphics g, pen p) {G. drawline (p, 50, 50,550,550);} Private Static void drawrec (Graphics g, pen p) {G. drawrectangle (p, 50, 50,500,500);} double pinghengxian (Double X) {return x/(2.47-1.47 * x/500) + 50;} static int F1 (int x) {return (INT) (0.662*(X-50)/500 + 0.297) * 500 + 50);} static int F2 (int x) {return (INT) (1.585 * (X-50)/500-0.026) * 500 + 50);} static int F3 (INT y) {return (INT) (double) (y-50)/500/(2.47-1.47 * (double) (y-50)/500) * 500 + 50);} the running result is as follows:


However, it would be much simpler to use MATLAB. The Code is as follows: I = 1; X (I) = 0.88; % initial liquid phase concentration Y (I) = 0.88; % vapor phase concentration initial value while (1) I = I + 1; X (I) = y (I-1)/(2.47-(2.47-1) * Y (I-1 )); % vapor-liquid equilibrium line equation if X (I) <0.35 break; end; y (I) = 1.96/2.96 * X (I) + 0.88/2.96; % Operating line equation of the final distillation section, among them, reflux ratio r = 1.96 endxd = 0.35; % q = 1, so XD = XF = 0.35yd = 1.96/2.96*0.35 + 0.88/2.96; % calculate the vapor phase concentration k = (yd-0.044)/(0.35-0.044) according to the operating line equation of the distillation section; % the slope of the Operating Line of the withdrawal section B = YD-K * 0.35; % extract segment operation line intercept while (1) y (I) = K * X (I) + B; X (I + 1) = y (I) // (2.47-(2.47-1) * Y (I); If X (I + 1) <0.044 y (I + 1) = K * X (I + 1) + B; break; end I = I + 1; endx2 (1) = 1; y2 (1) = 1; for n = 2: I + 1x2 (n) = x (n); Y2 (n) = y (n-1 ); endx2 (I + 1) = 0; Y2 (I + 1) = 0; plot (X, Y, x, y); % adjust any of them to the stair attribute hold on; GRID; plot (X2, Y2); X3 = 0: 0. 05; Y3 = X3; plot (X3, Y3); the result is as follows: we can see that using MATLAB to achieve this problem is similar to using computer programming languages, this greatly simplifies the design.3. Experiment Data ProcessingNext we will discuss the experiment data processing of "CO2 critical state observation and PVT relationship test" that we have done a few days ago. This experiment is mainly to measure some vapor-liquid data and then make a phase diagram. Based on the tested experiment data, write the following code: t = 290: 310; P1 = 10. ^ (7.837-1604.1. /(t + 100); plot (T, P1); hold; P2 = 10. ^ (7.76331-1566.08. /(t + 97.87); T3 = [293.15, 295.75, 297.3, 299.1, 301.31, 303.27]; P3 = [5750,6060, 6310,6540, 6920,7240, 304.3]; plot (T, P2, '--', T3, P3, 'O'); Title ('comparison between the tested vapor pressure data and the calculated value '); xlabel ('t/k'); ylabel ('P/KP '); legend ('Tested', 'document '); the final result is as follows:


It can be seen that the results obtained using Matlab are both simple and clear, and only a few simple lines of code can achieve amazing results.4. Linear FittingFinally, we will give an example of linear fitting. In the experiment of "Measuring polymerization reaction rate by expansion meter", the measured conversion rate and time data are as follows:

Time 3 6 9 12 15 18
Conversion Rate 0.00678 0.01982 0.03234 0.04643 0.05999 0.0735
To fit the linear relationship between time and conversion rate, write the following code: A = [0.00678, 0.01982, 0.03234, 0.04643]; B = [0.05999, 0.07355,]; [p, error] = polyfit (A, B, 1) xi = linspace (0, 21, 100); Z = polyval (p, xi); plot (A, B, 'o', XI, Z, '-'); xlabel ('t/min'), ylabel ('C'), title ('conversion rate (c) result: P = 0.0045-0.0070 error = R: [2x2 double] DF: 4 normr: 9.4423e-004


5. ConclusionThe role of MATLAB is far more than that. The above are just some basic applications. I believe it will be used more in my later learning process, it will bring more convenience to my learning.References[1] MATLAB introduction, Liu jiahai [2] Matlab Application in graphic design, Liu jiahai [3] Matlab Application in fitting and interpolation, liu jiahai [4] initial math arithmetic operation, Liu jiahai

 

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.