How find the value of V=V0,V1,...,Vn.

2 次查看(过去 30 天)
SHAHID
SHAHID 2024-6-12
评论: SHAHID 2024-6-13
close all
clc
function V=L(Z,r,m,n,u)
Z=2;
n=5;
m=5;
r=0.2;
h=1/m;
% First for loop
for i=0:n
xi=i/n;
% if condition for xi-r
if xi-r< r
lflag=1;
else
j=find(xi-r<Y,1)-1;
alpha=(xi-r-Y(j))/h;
V=Y(j)+alpha*(Y(j+1)-Y(j));
end
% if condition for xi+r
if xi+r>1-r
uflag=1;
else
k=find(xi+r>Y)+1;
alpha=(xi+r-y(k-1))/h;
W=y(k-1)+alpha(Y(k)-Y(k-1));
end
% lflag and uflag conditions for trapz
if lflag == 1 && uflag == 1
w(i+1) = h * trapz(u);
elseif lflag == 1
w(i+1) = h * trapz(u(1:k-1)) + (xi+r-Y(k-1))/2 * (u(k-1) + W);
elseif uflag == 1
w(i+1) = Y(j+1) - (xi-r)/2 * (V + u(j+1)) + h * trapz(u(j+1:end));
else
w(i+1) = Y(j+1) - (xi-r)/2 * (V + u(j+1)) + h * trapz(u(j+1:k-1)) + (xi+r-Y(k-1))/2 * (u(k-1) + W);
end
end
% Another for loop
n=5;
h=1/n;
for i=0:n
V(i+1)=Z/2*h*trapz(w(1:i+1));
end
end
disp(V);
u=u0,u1,...,un are unknown vectors between [0,1]. Y(j)=r+j/m(1-2r), y=y0,y1,...,ym.

回答(1 个)

Nipun
Nipun 2024-6-13
Hi Shahid,
I understand that you want to minimize the given expression subject to the constraints. Based on the shared information, I recommend using non-linear minimization option built-in in MATLAB to achieve the desired results.
Here is the link to documentation for "fmincon" function in MATLAB used to find minimum of constrained nonlinear multivariable function: https://www.mathworks.com/help/optim/ug/fmincon.html
Hope this helps.
Regards,
Nipun
  1 个评论
SHAHID
SHAHID 2024-6-13
Dear Sir, can you give suggestion for writing code with fmincon because its new for me. I will wait your response. Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by