matlab求系统根轨迹代码_MATLAB教程-台大郭彦甫-第十一节,含练习答案(有空可以再看,值得深究)...

11-方程式求根

一、Symbolic approach(通过符号方法求根)

(一)Problem Statement

1、Suppose you have a mathematical function

and you want to find
such that
,e.g.

2、How do you solve problem using MATLAB?

(1)Analytical Solutions(解析解)

(2)Graphical Illustration(图解法)

(3)Numerical Solutions(数值解)

(二)Symbolic Root Finding Approach(符号寻根法)

1、Performing mathematics on symbols,NOT numbers (对符号而不是数字进行数学运算)

2、The symbols math are performed using “symbolic variables”(符号数学是使用“符号变量”来执行的)

3、Using sym or syms to create symbolic variables

(1)示例代码:

syms 

输出结果:

e5a9d9bb9287903ae94d31e36b252708.png

(2)示例代码:

x 

输出结果:

1564f6388e4055ec2f9b02a5d4ea62db.png

(三)Symbolic Root Finding:solve()

1、Function solve finds roots for equations(函数解法求方程根)

示例代码:

syms 

输出结果:

380fc90309862f52dd5ac2b488b316d6.png

2、小练习

(1)

答案代码:

syms 

输出结果:

474b934038cebb31c31ba3c38bf8ded6.png

(2)

答案代码:

syms 

输出结果:

1452e159d4508b1631e4e003e09b64e5.png

(四)Solving Multiple Equations

1、Solve this equation using symbolic approach:

示例代码:

syms 

输出结果:

8d824320728d655bd2087fb4f8ed7afb.png

(五)Solving Equations Expressed in Symbols

1、What if we are given a function expressed in symbols

示例代码:

syms 

输出结果:

1d442de24d4989daf1e23ef04e5ee16e.png

2、What if one wants to express b in terms of a and x(若想通过a和x来表达x)

示例代码:

syms 

输出结果:

fcc36d90a877734497377956398c1b1a.png

(六)Excise

1、Solve this equation for x using symbolic approach(用符号方法解x的这个方)

答案代码:

syms 

输出结果:

4750be9dfde6e2e0f95e429f875f0b67.png

2、Find the matrix inverse using symbolic approach(用符号法求矩阵逆)

682531fd8be3c8adf5c46c7a27afca54.png

答案代码:

syms 

输出结果:

20f193a21f8c9b856443719ee1dcc5cb.png

(七)Symbolic Differentiation:diff()

1、Calculate the derivative of a symbolic function:

(计算符号函数的导数)

示例代码:

syms 

输出结果:

e01bc07d3b4b6d55403ba2be8aae54ab.png

2、练习

(1)

(2)

答案代码:

syms 

输出结果:

bd103a1490ad78d004134dfc0569fd70.png

(八)Symbolic Integration:int()

1、Calculate the integral of a symbolic function:

示例代码:

syms 

输出结果:

160bb112b498fc88dffc3f98f0e1b855.png

2、Excise:

答案代码:

syms 

输出结果:

f39fc27a437ca4bcd4a87a2ae3cee311.png

(九)Symbolic vs. Numeric

6873ea71f96eb3d86c58221f239e10dc.png

二、Numeric root solvers(利用数值求根)

(一)Review of Function Handles(@)(回顾函数句柄)

1、A handle is a pointer to a function(句柄是指向函数的指针)

2、Can be used to pass functions to other functions(可用于将函数传递给其他函数)

3、For example,the input of the following function is another function

示例代码:

function

输出结果:

xy_plot

cfa916a74a92790045b7eda333e050ea.png
xy_plot

e2f6a1ba3b3b664f3591a15d3e2b9ff4.png

(二)fsolve()

1、A numeric root solver

2、For example,solve this equation:

8a2ce76a3fc931c65c29b5de3137c57f.png

示例代码:

f2 

输出结果:

8f0fb0110edc8891e12803fae89c10d0.png

注意:

(1)f2 =@(x)(1.2*x +0.3+ x *sin(x));其中的@(x)为匿名函数,第一个括号里面是自变量,第二个括号里面是表达式,@是函数指针。

@在匿名函数中表示函数句柄。例如ln(x),在matlab中是没有定义的,正确表示是log(x);

但如果要直观表示自然对数,意义用以下语句表示:

ln=@(x) log(x);

(2)fsolve:求解非线性方程组

matlab中利用 solve,fzero,fsolve解方程问题​www.cnblogs.com

3、Excise

(1)Find the root for this equation

33e7f75b76162a83bb5b61a1475fb473.png

答案代码:

f

输出结果:

0f1922e6634c34b67e210460440c76c2.png

(三)fzero()

1、Anther numeric root solver(另一种数值根解法)

2、Find the zero if and only if the function crosses the x-axis

7d307ac28cd290a47c08c1c727a9504c.png

1e1834a715b27a7c18af4419d8dbe021.png

3、示例代码:

f 

输出结果:

2b3d086230c80b42a2c926974065969f.png

4、Option:(似乎失败了,没有出现准确的值,和上面的值相同)

示例代码:

f 

输出结果:

d1adce75bca9b30b6c087bbfd0cdf4dd.png

(四)Finding Roots of Polynomials:roots()

1、Find the roots of this polynomial:

示例代码:

roots

输出结果:

aa93e6d5186f81e966c8d7f807968464.png

2、roots only works for polynomials

3、Excise:Find the roots of the polynomial:

答案代码:

roots

输出结果:

9a948bb1e4fe74e6c9aec7432997c0a5.png

(五)Hwo Do These Solvers Find the Roots?

1、Now we are going to introduce more details of some numeric methods

45ae2f945a2baf486e29ab98ab204a48.png

(六)Numeric Root Finding Methods(数值求根方法)

1、Two major types:(两种)

(1)Bracketing methods(e.g.,bisection method)(包夹,如二分法)

Start with an interval that contains the root(从包含根目录的间隔开始)

(2)Open method(e.g.,Newton-Raphson method)(无包夹,如牛顿法)

Start with one or more initial guess points(从一个或多个初始猜测点开始)

2、Roots are found iteratively until some criteria are satisfied(迭代找到根,直到满足某些条件)

(1)Accuracy(更精确)

(2)Number of iteration(迭代次数)

(七)Bisection Method(Bracketing)(即二分法),很重要,值得好好理解

445033655f7a840c9dea6c6e5e1ba4f7.png

1、Assumptions:(假设)

continuous on [l,u](函数在区间内连续)

(函数有穿过x轴,即被x轴分割)

2、Algorithm(算法)

(八)Bisection Algorithm Flowchart(等分算法流程图)

67cd268960a96e29123da494aab131cb.png

(九)Newton-Raphson Method(Open)(牛顿拉普森法)

fc6b099e8b21daa4ace20070702a5f72.png

1、Assumptions:(假设)

continuous(函数连续)

(函数的导数已知,即函数连续可导)

2、Algorithm(算法)

(十)Newton-Raphson Algorithm Flowchart(牛顿法流程图)

e95b167b2e50ba6f324d2f1f49dd4d21.png

(十一)Bisection vs. Newton-Raphson

8d9b24ab1147fa53b481140b5917d8db.png

三、Recursive functions(利用递归求根)

1、Function that call themselves

2、Example,factorial of an integer n

n! = 1X2X3X...Xn

3、A factorial can be defined in terms of anther factorial:

fde2e001261c3784b587502aaade8939.png

(一)Factorial Recursive Function(阶乘递归函数)

1、The function includes a recursive case and a base case(该函数包括递归情况和基情况)

2、The function stop when it reaches the base case(函数到达基本情况时停止)

e223ebfb4898275381ad5c45b1523ccc.png

第十一节结束

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值