You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Function for linearization of nonlinear system of equations
3 views (last 30 days)
Show older comments
- 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 Comments
Alan Stevens
on 12 Nov 2020
Why do you want to linearize it? The function fminsearch can work with nonlinear equations.
HN
on 12 Nov 2020
Edited: HN
on 16 Nov 2020
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
on 12 Nov 2020
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
on 12 Nov 2020
Edited: HN
on 12 Nov 2020
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
on 12 Nov 2020
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
on 12 Nov 2020
Edited: HN
on 12 Nov 2020
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
on 16 Nov 2020
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
on 16 Nov 2020
Walter iacomacci Thank you,
I don't have model in simulink. I hope I can convert the program above easily. right ?
Walter iacomacci
on 16 Nov 2020
If you have the actual differential equation you can recreate it easily in Simulink. Here is an example:
Which is a Differential Equation System of a Circuit, the Block diagram looks like this with Vin=30
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.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)