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

조회 수: 1 (최근 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.
  댓글 수: 2
Aquatris
Aquatris 2024년 6월 12일
What exactly is the question?
SHAHID
SHAHID 2024년 6월 12일
I want to minimize this function.

댓글을 달려면 로그인하십시오.

답변 (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