当前位置:网站首页>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 .
边栏推荐
- AcWing 786. Number k
- Move anaconda, pycharm and jupyter notebook to mobile hard disk
- The "booster" of traditional office mode, Building OA office system, was so simple!
- LeetCode 324. 摆动排序 II
- Find the combination number acwing 886 Find the combination number II
- LeetCode 535. Encryption and decryption of tinyurl
- [point cloud processing paper crazy reading classic version 11] - mining point cloud local structures by kernel correlation and graph pooling
- [point cloud processing paper crazy reading classic version 10] - pointcnn: revolution on x-transformed points
- Recommend a low code open source project of yyds
- 【点云处理之论文狂读经典版10】—— PointCNN: Convolution On X-Transformed Points
猜你喜欢
On a un nom en commun, maître XX.
Basic knowledge of network security
LeetCode 57. Insert interval
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
Gaussian elimination acwing 883 Gauss elimination for solving linear equations
状态压缩DP AcWing 91. 最短Hamilton路径
【点云处理之论文狂读经典版9】—— Pointwise Convolutional Neural Networks
[point cloud processing paper crazy reading classic version 9] - pointwise revolutionary neural networks
MySQL installation and configuration (command line version)
LeetCode 715. Range 模块
随机推荐
Internet Protocol learning record
樹形DP AcWing 285. 沒有上司的舞會
AcWing 785. 快速排序(模板)
传统企业数字化转型需要经过哪几个阶段?
2022-2-14 learning xiangniuke project - Session Management
Find the combination number acwing 885 Find the combination number I
What are the stages of traditional enterprise digital transformation?
【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion
Use of sort command in shell
Simple use of MATLAB
LeetCode 241. Design priorities for operational expressions
Data mining 2021-4-27 class notes
LeetCode 508. 出现次数最多的子树元素和
Digital management medium + low code, jnpf opens a new engine for enterprise digital transformation
Basic knowledge of network security
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
C language programming specification
Methods of using arrays as function parameters in shell
【点云处理之论文狂读前沿版13】—— GAPNet: Graph Attention based Point Neural Network for Exploiting Local Feature