Home Database Mysql Tutorial Matlab的基本应用2

Matlab的基本应用2

Jun 07, 2016 pm 03:14 PM
matlab one main share Basic application

这一节主要分享一下利用MATLAB进行相关计算。MATLAB内置了很多计算方法及其函数实现,即使不懂数方法,也可以进行一些复杂的计算,例如有求解矩阵的逆,求解积分、微分,进行傅里叶变化及其逆变换,进行最小二乘法的直线拟合等等。 例1、 求解一个矩阵的逆矩

这一节主要分享一下利用MATLAB进行相关计算。MATLAB内置了很多计算方法及其函数实现,即使不懂数值方法,也可以进行一些复杂的计算,例如有求解矩阵的逆,求解积分、微分,进行傅里叶变化及其逆变换,进行最小二乘法的直线拟合等等。


例1、求解一个矩阵的逆矩阵,并进行矩阵的乘计算。

首先是输入(或者说是定义)一个矩阵a,那么则应输入的是:

>> a=[1 2;3 4]

若无分号,直接回车,则会输出a矩阵。

求a矩阵的逆矩阵,求解利用的函数如下:

>> b=inv(a)

计算矩阵相乘,在这里计算a矩阵乘以b矩阵的转置,而矩阵的转置则只需加一撇即可:

>> c=a*b'

最后输出的结果有:

a =                               
     1     2
     3     4

b =
   -2.0000    1.0000
    1.5000   -0.5000

c =
         0    0.5000
   -2.0000    2.5000

b' =
   -2.0000    1.5000
    1.0000   -0.5000


例2、符号运算的定义,主要有syms,sym的应用,如下:

这两种皆为定义符号,但又有些许区别。syms是在运用符号之前,将所用的符号全部定义,下面则可以直接运用;而sym则是在运算中定义,用到每一个符号需要定义一次,相对而言没有syms方便,下面有具体例子。

 如:syms x(t) a

               就等于

                  a = sym('a');
                   t = sym('t');
                  x = symfun(sym('x'), {t});


          syms x beta real

               就等于

                  x = sym('x','real');
            beta = sym('beta','real');

上面的syms先定义了几个是函数符号,下面就可以直接运用,公式中不用再出现sums或者sym,而sym则是在下面的公式中出现的。


例3、求积分及微分,运用MATLAB函数int以及diff,由于牵涉到符号运算,所以在运用之前,需要利用syms做一下符号的定义,如下:

 syms x

int(x)   按回车后,得到

ans =
 x^2/2

也可以直接输入int(sym(x))  按回车后得到

ans =
 x^2/2

当然,也可以进行比较复杂积分计算,因为可能会牵涉到较多的符号,所以建议大家利用syms先将用到的符号定义好,在利用int函数,进行积分计算。

微分计算函数diff,运用方式和int基本类似,例如

>> syms x y
>> y=diff(sin(x))

y =
 cos(x)

真正灵活运用这些MATLAB函数,还是需要大家不断尝试和运用的。


例4、solve和dsolve函数的应用

这两个函数均可以用于解函数方程或者方程组,solve主要用于解一般的方程及方程组,而dsolve则一般用于求解微分方程组,具体例子如下:

如求解方程sin(x)*pi=8,求x

>> solve('sin(x)*pi=8')

ans =
      asin(8/pi)
 pi - asin(8/pi)

这里默认求解的是x,如果是>> solve('sin(x)*pi*y=8'),那么依旧默认求解的是x,那如果想输出y呢?则需要>> solve('sin(x)*pi*y=8','y'),那么会输出ans =8/(pi*sin(x));



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Undo Delete from Home Screen in iPhone How to Undo Delete from Home Screen in iPhone Apr 17, 2024 pm 07:37 PM

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments How to share NetEase Cloud Music to WeChat Moments_Tutorial on sharing NetEase Cloud Music to WeChat Moments Mar 25, 2024 am 11:41 AM

1. First, we enter NetEase Cloud Music, and then click on the software homepage interface to enter the song playback interface. 2. Then in the song playback interface, find the sharing function button in the upper right corner, as shown in the red box in the figure below, click to select the sharing channel; in the sharing channel, click the "Share to" option at the bottom, and then select the first "WeChat Moments" allows you to share content to WeChat Moments.

The role and practical application of arrow symbols in PHP The role and practical application of arrow symbols in PHP Mar 22, 2024 am 11:30 AM

The role and practical application of arrow symbols in PHP In PHP, the arrow symbol (->) is usually used to access the properties and methods of objects. Objects are one of the basic concepts of object-oriented programming (OOP) in PHP. In actual development, arrow symbols play an important role in operating objects. This article will introduce the role and practical application of arrow symbols, and provide specific code examples to help readers better understand. 1. The role of the arrow symbol to access the properties of an object. The arrow symbol can be used to access the properties of an object. When we instantiate a pair

From beginner to proficient: Explore various application scenarios of Linux tee command From beginner to proficient: Explore various application scenarios of Linux tee command Mar 20, 2024 am 10:00 AM

The Linuxtee command is a very useful command line tool that can write output to a file or send output to another command without affecting existing output. In this article, we will explore in depth the various application scenarios of the Linuxtee command, from entry to proficiency. 1. Basic usage First, let’s take a look at the basic usage of the tee command. The syntax of tee command is as follows: tee[OPTION]...[FILE]...This command will read data from standard input and save the data to

How to share files with friends on Baidu Netdisk How to share files with friends on Baidu Netdisk Mar 25, 2024 pm 06:52 PM

Recently, Baidu Netdisk Android client has ushered in a new version 8.0.0. This version not only brings many changes, but also adds many practical functions. Among them, the most eye-catching is the enhancement of the folder sharing function. Now, users can easily invite friends to join and share important files in work and life, achieving more convenient collaboration and sharing. So how do you share the files you need to share with your friends? Below, the editor of this site will give you a detailed introduction. I hope it can help you! 1) Open Baidu Cloud APP, first click to select the relevant folder on the homepage, and then click the [...] icon in the upper right corner of the interface; (as shown below) 2) Then click [+] in the "Shared Members" column 】, and finally check all

Explore the advantages and application scenarios of Go language Explore the advantages and application scenarios of Go language Mar 27, 2024 pm 03:48 PM

The Go language is an open source programming language developed by Google and first released in 2007. It is designed to be a simple, easy-to-learn, efficient, and highly concurrency language, and is favored by more and more developers. This article will explore the advantages of Go language, introduce some application scenarios suitable for Go language, and give specific code examples. Advantages: Strong concurrency: Go language has built-in support for lightweight threads-goroutine, which can easily implement concurrent programming. Goroutin can be started by using the go keyword

How to share ppt How to share ppt Mar 20, 2024 pm 07:51 PM

People in the workplace will be familiar with PPT production, because whether it is a year-end summary or a work report, many companies require it to be presented in the form of PPT. At this time, I encountered a problem, that is, how to share PPT? Don’t worry, the editor below will show you how to share PPT. 1. First select the edited PPT and click Save in the upper left corner (if you are using WPS, you can click Login first). 2. Then click the share icon in the menu bar as shown below. 3. Then the sharing interface as shown below will pop up. You can see that a sharing link will appear. Click to send the link to share. 4. You can also click "Allow friends to edit" in the lower left corner of the picture below, so that friends can also click to edit this PPT. 5. If necessary, give P

The wide application of Linux in the field of cloud computing The wide application of Linux in the field of cloud computing Mar 20, 2024 pm 04:51 PM

The wide application of Linux in the field of cloud computing With the continuous development and popularization of cloud computing technology, Linux, as an open source operating system, plays an important role in the field of cloud computing. Due to its stability, security and flexibility, Linux systems are widely used in various cloud computing platforms and services, providing a solid foundation for the development of cloud computing technology. This article will introduce the wide range of applications of Linux in the field of cloud computing and give specific code examples. 1. Application virtualization technology of Linux in cloud computing platform Virtualization technology

See all articles