Function for linearization of nonlinear system of equations
4 次查看(过去 30 天)
显示 更早的评论
- V =F(rp,x1,x2,theta(t), psi(t), phi(t),wx(t),wy(t) ) is a non linear equation and the objective is to minimize output vector V for the given optimization variables rp, x1 and x2. Can anyone recommend me a method to linearize it using matlab ?
10 个评论
Alan Stevens
2020-11-12
Why do you want to linearize it? The function fminsearch can work with nonlinear equations.
HN
2020-11-12
编辑:HN
2020-11-16
Alan Stevens , rp,x1,x2 are bounded. So, I wanted to use constrained optimization. I couldn't implement fmincon because V is a vector. I wanted to get the minimum of V(1),V(2),V(3) simultaneously. Can I still use fminsearch ? (rp,x1,x2) = (rp,xi_2,xi_3).
Below is the function I wanted to minimize . Thank you.
function V = Opt_QN(rp,xi_2,xi_3)
L=1;
z=0.7071068;
ts=1/2;
t=0:ts:1;
for k=1:length(t)
xi_2=beta(k);
rp=radius(k);
for j=1:length(t)
xi_1=0;
xi_2=alpha(j);
xi_3=beta(j);
th(j)=-0.2*cos(2*pi*t(j));
psi(k)=0.2*sin(2*pi*t(k));
phi(j)=atan2(sin(psi(k))*sin(th(j)),(cos(psi(k))+cos(th(j))));
R=Rot('y',th(j))*Rot('x',psi(k))*Rot('z',phi(j));
x(k)=1/2*rp*(-cos(phi(j))*cos(psi(k))+cos(phi(j))*cos(th(j))+sin(phi(j))*sin(psi(k))*sin(th(j)));
y(k)=-rp*cos(psi(k))*sin(phi(j));
zc(k)=z;
delta(k)=sqrt(x(k)^2+y(k)^2)
p=[x(k);y(k);zc(k)];
end
end
end
Alan Stevens
2020-11-12
You pass rp, xi_2 and xi_3 to the function, but almst immediately reassign them, so the input values do nothing!
Your output is a vector, so what is your minimization measure?
If you have access to the Optimisation toolbox you will have more options than fminsearch.
HN
2020-11-12
编辑:HN
2020-11-12
Alan Stevens, I tried to use fmincon but I can't trust the result. It is also difficult to find global minimum and corresponding optimum parameters. Moreover, the computation time is quite long. Did I do something wrong in the double four loop shown below to call the function ? Yes, I have the toolbox.
%main program
clc
close all
%% UB LB setting
x2L = deg2rad(90);
x2U = deg2rad(150);
x3U = deg2rad(-90);
x3L = deg2rad(-150);
x2=x2L:(x2U-x2L)/ts:x2U;
x3=x3L:(x3U-x3L)/ts:x3U;
A = [];
b = [];
Aeq = [];
beq = [];
%%
LB = [deg2rad(90), deg2rad(-150)]; % 120 =2.0944 , 150 =-2.6180
UB= [deg2rad(150), deg2rad(-90)];
options = optimoptions('fmincon','Algorithm','interior-point','SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,'Display' ,'iter');
options = optimoptions(options,'SpecifyObjectiveGradient',false,'SpecifyConstraintGradient',false);
% %% Plot
[X,Y] = meshgrid(x2,x3);
for idx =1:length(x2)
for jdx=1:length(x3)
x12 = [x1(idx) , x2(jdx)];
fun = @(x)PRSopt_QN(x)
[V,S]=fun(x12);
[Vec,Fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x12,[],[],[],[],LB,UB, [],options);
Min(idx,jdx)=Fval;
[xs,index]= sort(Min)
result = Min(sort(index(1:x1)));
Opt(:,idx)=Vec ;
Average(idx,jdx)=V;
end
end
Mini=min(Min,[],'all');
figure,
contour3(X,Y,Average*100,'color','blue','ShowText','on');
title('Function evaluation')
hLeg=legend({''},'FontSize',12);
set(hLeg,'Interpreter','latex');
box off;
xlabel('\xi_1')
ylabel('\xi_2')
zlabel('mm/s')
figure,contour3(X,Y,Min,'color','blue','ShowText','on');
title('Function evaluation')
hLeg=legend({''},'FontSize',12);
set(hLeg,'Interpreter','latex');
box off;
xlabel('\xi_1')
ylabel('\xi_2')
zlabel('mm/s')
figure, surf(X,Y,Min)
figure, surf(X,Y,Average*100)
hLeg=legend({''},'FontSize',12);
set(hLeg,'Interpreter','latex');
box off;
title('Optimized linear velocity ')
xlabel('\xi_1')
ylabel('\xi_2')
zlabel('mm/s')
% [vout, fout] = fmincon(fun,x);
HN
2020-11-12
Alan Stevens, the output V elements are hetrogeneous physical models. So, I am confused how can I set minimization measure. My plan was to minimize each elements separately.
Thank you
HN
2020-11-12
编辑:HN
2020-11-12
John D'Errico , I am just afraid if my assignment/difinition of input variables is not suitable to fmincon. Would you please share me your rough assesment on the following lines of calling the fucntion ? Thank you
% %% Plot
x2L = deg2rad(90);
x2U = deg2rad(150);
x3U = deg2rad(-90);
x3L = deg2rad(-150);
x2=x2L:(x2U-x2L)/ts:x2U;
x3=x3L:(x3U-x3L)/ts:x3U;
[X,Y] = meshgrid(x2,x3);
for idx =1:length(x2)
for jdx=1:length(x3)
x12 = [x1(idx) , x2(jdx)];
fun = @(x)PRSopt_QN(x)
[V,S]=fun(x12);
[Vec,Fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x12,[],[],[],[],LB,UB, [],options);
Min(idx,jdx)=Fval;
[xs,index]= sort(Min)
result = Min(sort(index(1:x1)));
Opt(:,idx)=Vec ;
Average(idx,jdx)=V;
end
end
Walter iacomacci
2020-11-16
Have you tried making the Block diagram of that differential equation with Simulink?
If you have a model in Simulink there is a pretty useful command called linmod which is easy to use, the thing is that it will linearize the model for you in terms of a State-space model (A,B,C,D) matrices which I dont know if works for you.
HN
2020-11-16
Walter iacomacci Thank you,
I don't have model in simulink. I hope I can convert the program above easily. right ?
Walter iacomacci
2020-11-16
If you have the actual differential equation you can recreate it easily in Simulink. Here is an example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/415378/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/415383/image.png)
Which is a Differential Equation System of a Circuit, the Block diagram looks like this with Vin=30
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/415388/image.png)
Ignore the gain with 1/4 going to VL it is just a relation to obtain the values in time for a voltage in the inductor.
If you have only 1 differential equation is much easier. Let me know if you need help.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)