当前位置:网站首页>Matlab - polynomial and function
Matlab - polynomial and function
2022-06-09 05:31:00 【kaims】
polynomial
The representation of polynomials
One p A polynomial of order can be expressed as a polynomial containing p+1 Vector representation of elements ,MATLAB Denotes that a polynomial is a row vector containing coefficients arranged by descending powers , for example
p(x)=2*x^2+1
It can be expressed as
p = [2 0 1];
conv
Multiplication of polynomials .
p1=[1 1];% It is x+1 The coefficient matrix of
p2=[1 0];% It is x The coefficient matrix of
P=conv(p1,p2)
P=
1 1 0
%P=[1 1 0], Explain that the multiplied polynomial is x^2+x
poly
- Construct polynomials with roots . Such as x The root of a polynomial ,**poly(x)** The coefficients of the polynomial are obtained ;
- Generating characteristic polynomials of matrices . Such as A Is a matrix ,**poly(A)** The coefficients of the characteristic polynomial of the matrix can be obtained ;
polyval
y=polyval(p,x);% According to the polynomial coefficient matrix p Seek for x Place the value of the
roots
x=roots(p);% Find a polynomial p The root of the
polyder
polyder(p);% For polynomials p Derivation
polyfit
p = polyfit(x,y,n);% According to the data point set (x,y) Fit a polynomial , The highest power of a polynomial is n, Returns the polynomial coefficient matrix
sym2poly
Through function expression ( Symbolic functional form ) Generate coefficient matrix
p=sym2poly(f);
poly2sym
The expression of polynomial function is generated by coefficient matrix ( Symbolic functional form )
f=poly2sym(p);
Symbolic function (Symbolic Function)
notes : Under this section matlab Code shares variables
adopt syms Defining variables , Write function expressions directly , This defines a symbolic function y
syms p q x y
p=x^2;
q=x^2+y^2;
The symbolic function image can be drawn through the function fplot( A two-dimensional ),ezplot( A two-dimensional ),ezsurf( The three dimensional ),ezmesh( The three dimensional )
ezplot(p);% Or define the scope ezplot(p,[-5,5]);
fplot(p);% ditto
ezsurf(q);% Or define the scope ezsurf(q,[-1,1]); perhaps ezsurf(q,[-1,1],[-1,1]);
ezmesh(q);% ditto
Find the value of a symbolic function at a certain place ,
- One way is through a function matlabFunction Turn a symbolic function into an anonymous function , Then calculate the function value
f1=matlabFunction(p)
f2=matlabFunction(q)
f1(3)
f2(1,2)
% The result is :
f1 =
@(x)x.^2
f2 =
@(x,y)x.^2+y.^2
ans =
9
ans =
5
attach : Conversion between anonymous function and symbolic function
The above is about the conversion of symbolic functions to anonymous functions , Let's look at the conversion of anonymous functions to symbolic functions
[email protected](t)t.^2;
syms t
f4=f3(t) %f4 Is the converted symbolic function
- Another way is through the function eval Directly find the value of a symbolic function at a certain place , First of all, I need to give x Assign a specific value
x=1;y=2;
eval(p)
eval(q)
% The result is
ans =
1
ans =
5
- Another way is through the function subs Directly find the value of a symbolic function at a certain place
subs(p,1) %subs(p,x,1)
subs(q,[1 2]) %subs(q,[x y],[1 2])
% The result is
ans =
1
ans =
5
% in addition ,subs(q,y,2) You'll get x^2+4
String function
- String to function
str2func
fh = str2func(str)
% Constructor handles based on function names or textual representations of anonymous functions fh
- Function to string
func2str
c = func2str(fh)
% Construct character vectors c, The character vector contains the function handle fh The name of the associated function . If fh Associated with anonymous functions , be %func2str Returns the character vector representing the anonymous function .
Anonymous functions (Anonymous Function)
Find the zero of the function
roots
Find the zero point function by polynomial
fzero
Find a numerical solution near a given initial value / Returns the zero point of a unary function in an interval
% Invocation format :
x=fzero(fun,x0) %fun Is a function that defines an equation or an anonymous function ;x0 Is a value or interval , As an initial condition
We can only find a zero point in the interval , And the function value at the end of a given interval is required to have a different sign , So you should draw before using , Get the interval of single zero distribution , Then use this function to find the zero point . If there are multiple zeros , You need to use this function more than once .
fminbnd
Find the minimum value of a unary function in a certain interval and the corresponding minimum value point .
% Invocation format :
[x0,fmin]=fminbnd(fun,a,b);%fun Is a function that defines an equation or an anonymous function ; Interval is [a b]
solve
syms x
solve(2*x==1,x) % It's not recommended right now solve('2*t=1','t')
% The result is
ans =
1/2
边栏推荐
- LRU cache
- redis 缓存雪崩、穿透、击穿问题
- Detailed introduction to arrays and linked lists
- AQS 之 ReentrantReadWriteLock 源码分析
- Esmascript 6.0 advanced
- Palindrome linked list leetcode
- [C language] a quick pass operator
- The 27th issue of product weekly report | members' new interests of black users; CSDN app v5.1.0 release
- (Application of reflection + introspection mechanism) processing the result set of JDBC
- readme. md
猜你喜欢

IP address division and subnet

Requests segmented downloading of files and multi-threaded downloading

redis 分布式锁的几种实现方式

内网渗透 - 哈希传递攻击

Cmdbuilding搭建简易流程及问题处理

使用MAT进行内存问题定位

Load research of Marathon LB

TCP explanation (Wireshark packet capturing analysis TCP three handshakes and TCP four waves)

AI video cloud: a good wife in the era of we media

【IT】福昕pdf保持工具選擇
随机推荐
Simple process and problem handling of cmdbuilding
Mysql 添加字段或者创建表SQL语句
Alibaba cloud AI training camp MySQL foundation 1:
Heap and priority queues
Good hazelnut comes from Liaoyang!
Number that appears only once -leetcode
Missing digit JS in sword finger 0~n-1
Intranet penetration hash delivery attack
[it] Foxit PDF retention tool selection
Morsel-Driven Parallelism: 一种NUMA感知的并行Query Execution框架
Web page capture software
Apache devlake code base guide
Linked list
The 27th issue of product weekly report | members' new interests of black users; CSDN app v5.1.0 release
Palindrome linked list leetcode
Deque of STL
Thinking about global exception capture - real global exception capture
Requests segmented downloading of files and multi-threaded downloading
When classical music meets NFT
How to build fastdfs, vsftpd and miniio file servers in marathon environment