当前位置:网站首页>Matlab dichotomy to find the optimal solution
Matlab dichotomy to find the optimal solution
2022-07-03 09:16:00 【Fingering 13】
MATLAB Dichotomy to find the optimal solution
【 Vegetable dog bb】emm… The principle is quite simple , There should be nothing you don't understand . Is to give a function f And interval [a,b] And accuracy esp, Take the derivative of the intermediate value of the interval , Less than 0 Just assign the intermediate value to a, Greater than 0 Just assign the intermediate value to b. If the derivative equals 0 perhaps b-a The value is less than esp No longer judge , The intermediate value is the abscissa of the optimal solution .
No grinding , Look at the code or :
Here are some .
function [k,y]=erfenfa1(f,a,b,esp)
syms x;
% f Is the function given a,b For the given interval ,eps For accuracy
% Return value [k,y] Is the horizontal and vertical coordinates of the optimal solution
while b-a > esp
% Find out in a,b The derivative of the intermediate point
zhong = (b+a)/2;
dao = subs(diff(f),x,zhong);
% If the reciprocal is 0, be a,b In the middle zhong Is the abscissa of the optimal solution
if dao == 0
k=zhong;
y = subs(f,x,zhong);
break;
else
% The derivative is less than 0 take zhong Assign a value to a, Greater than 0 Assign to b
if(dao<0)
a = zhong;
else
b = zhong;
end
end
% When b-a Less than esp when , take a,b The midpoint is the abscissa of the optimal solution ,y Vertical coordinates
if b-a<=esp
k =(b+a)/2;
y = subs(f,x,k);
end
end
emm… Look at a simple test case :
>> clear
>> syms x;
f = x^2 + 2*x -1;
[x,y] = erfenfa1(f,-2,0,0.1);
>> [x,y]
ans =
[ -1, -2]
emm… One more piece ,,, Give me a compliment and I'll show you again , how ..( Manually cheat like )
Bye-bye , Hey .
边栏推荐
- 状态压缩DP AcWing 91. 最短Hamilton路径
- Methods of checking ports according to processes and checking processes according to ports
- 【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion
- 【Kotlin学习】运算符重载及其他约定——重载算术运算符、比较运算符、集合与区间的约定
- LeetCode 75. 颜色分类
- 2022-1-6 Niuke net brush sword finger offer
- With low code prospect, jnpf is flexible and easy to use, and uses intelligence to define a new office mode
- Gaussian elimination acwing 883 Gauss elimination for solving linear equations
- AcWing 786. 第k个数
- 20220630 learning clock in
猜你喜欢
![[point cloud processing paper crazy reading classic version 7] - dynamic edge conditioned filters in revolutionary neural networks on Graphs](/img/0a/480f1d1eea6f2ecf84fd5aa96bd9fb.png)
[point cloud processing paper crazy reading classic version 7] - dynamic edge conditioned filters in revolutionary neural networks on Graphs

LeetCode 532. K-diff number pairs in array

Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?

2022-2-14 learning the imitation Niuke project - send email

Computing level network notes

LeetCode 241. 为运算表达式设计优先级

2022-2-13 learning the imitation Niuke project - home page of the development community

LeetCode 871. 最低加油次数

【点云处理之论文狂读经典版14】—— Dynamic Graph CNN for Learning on Point Clouds

LeetCode 57. Insert interval
随机推荐
Pic16f648a-e/ss PIC16 8-bit microcontroller, 7KB (4kx14)
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
LeetCode 30. Concatenate substrings of all words
[point cloud processing paper crazy reading classic version 12] - foldingnet: point cloud auto encoder via deep grid deformation
Liteide is easy to use
LeetCode 324. 摆动排序 II
[point cloud processing paper crazy reading classic version 11] - mining point cloud local structures by kernel correlation and graph pooling
2022-2-14 learning the imitation Niuke project - send email
[point cloud processing paper crazy reading classic version 7] - dynamic edge conditioned filters in revolutionary neural networks on Graphs
LeetCode 508. 出现次数最多的子树元素和
LeetCode 241. Design priorities for operational expressions
Wonderful review | i/o extended 2022 activity dry goods sharing
2022-2-13 learning xiangniuke project - version control
Introduction to the usage of getopts in shell
AcWing 786. Number k
LeetCode 715. Range module
LeetCode 515. 在每个树行中找最大值
Using variables in sed command
What are the stages of traditional enterprise digital transformation?
<, < <,>, > > Introduction in shell