Optimize function while meeting a condition
조회 수: 4 (최근 30일)
이전 댓글 표시
How can i optimize the I function, i want to find the values of h(j) that minimize I, meetentig the condition h(j+1)>h(j)?
Thanks for the help
function [h] = peralte(v,rt,Lc,Lt,s)
lt=0:0.1:Lt;
lc=0:0.1:Lc;
for i=1:length(lt)
for j=1:length(lc)
ht(i,j)=(((v(i,j)).^2)*s)/(rt(j)*9.81);
end
end
for i=1:length(lt)
for j=1:length(lc)
I(i,j)=ht(i,j)-h(j);
end
end
end
댓글 수: 0
답변 (2개)
William Rose
2023년 4월 13일
Please explain your function in more detail. It is good practice to include comments in a function eplaining the meaning and size (if not scalars) of all input and output arguments.Is it true that function peralte(v,rt,Lc,Lt,s) returns a vector of length Lt+1? Is v an array? What is its physical meaning? Why does g=9.81 appear?
Your function never assigns a value to h. Therefore it is not complete.
If you want to adjust h to minimize I, then you should define a function I(h), which takes h as an argument and returns I. By the way, I try to avoid using upper case I (eye) or lower case l (ell) as names of functions or variables, since they look the same.
When you have defined I(h), you can try one of matlab's minimization routines. fmincon() is a good place to start. It is not yet clear to me if fmincon() can implement the constraint you specified. But first let's figure out h() and I(h) more clearly.
댓글 수: 7
William Rose
2023년 4월 20일
Of course the bank angle needed, in order to keep the train's ground reaction force,
, perpendicular to the train bed is
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361658/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361663/image.png)
but your formula for
is not the formula above. You have a factor of s, which I do not understand, and you do not use the inverse tanget formula.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361668/image.png)
Can you work out the formula for
, the bank angle needed to keep the force vector pointed inside the outer rail? Assume the center of mass height above the unbanked track is
, and assume the rail gauge is
. I get
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361673/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361678/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361683/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361688/image.png)
I could be wrong, so you should check my formula to see if it is correct. I use the max() function so that the formula will not give negative values for bank angle when the velocity is low. I assume each rail is strong enough to withstand any force applied to it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361693/image.png)
Approximate values for
are 2.0 to 2.5 m (see here and here). Standard gauge is 1435 mm, so a reasonable value for
is 0.72 m.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361698/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361703/image.png)
In 2015, a train derailed near my home, as it went around a curve. Eight people died and over 200 were injured. The speed limit was 80 kph. The train was going 164 kph when it derailed. I estimated the radius of curvature by adjusting a circle to match the curve, on a screenshot from google maps. See below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361708/image.png)
William Rose
2023년 4월 20일
@Jon Bilbao, the link to the Wikipedia article is helpful. Now I understand that cant has units of length, not angle.
I cannot assist you if you do not answer the quesitons I have already asked. It will help if you include detailed comments in each function. For example, in function v=velTren2(), please fill in the missing information in the comments below. :
function [v] = VelTren2(v0,a,Lt,Lc)
%Velocidades de entrada a la curva de los ejes del tren
% Inputs
% v0 = [explain the meaning of v0] (m/s)
% a = [explain the meaning of a] (specify units for a)
% Lt = [explain meaning of Lt] (specify units for Lt)
% Lc = [explain meaning of Lc] (specify units for Lc)
% Output
% v = velocity (NxM array, where N~=10*Lt+1, M~=10*Lc+1) (m/s)
lt=0:0.1:Lt;
lc=0:0.1:Lc;
v(1)=v0;
for i=2:length(lt)
vi(i)=((v0.^2)+2*a*lt(i)).^(1/2);
for j=1:length(lc)
v(i,j)=((vi(i).^2)+2*a*lc(j)).^(1/2);
end
end
end
Please add similar comments to function h=peralte().
Please answer my previous request to explain, in detail, the significance of i and j, in the array v(i,j), in function velTren2(). What does v(1,2) refer to, compared to v(2,1) or v(2,2) or v(1,1)? A diagram would be helpful.
In function v=velTren2(), you assign a value to v(1). This is confusing, since v is a 2-D array. v(1) will be interpreted by Matlab as a reference to v(1,1). The code never assigns a value to v(1,2) or v(1,3) or v(1,4), etc. Therefore these array elements will be zero when the function returns. Is this what you want?
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!