Optimize function while meeting a condition

5 vues (au cours des 30 derniers jours)
Jon Bilbao
Jon Bilbao le 13 Avr 2023
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

Réponses (2)

William Rose
William Rose le 13 Avr 2023
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 commentaires
William Rose
William Rose le 20 Avr 2023
Of course the bank angle needed, in order to keep the train's ground reaction force,, perpendicular to the train bed is
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.
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
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.
= vector sum of vertical force (mg) and horizontal force (mv^2/r).
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.
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.
Jon Bilbao
Jon Bilbao le 20 Avr 2023
s is the width of the train.
The thing is that the value that i want to calculate is the cant (Cant (road/rail) - Wikipedia) of the railway so because of that the formula i use is h=v^2*s/gr. With your formula i understand taht the h calculathed is the position of the trains gravity center.

Connectez-vous pour commenter.


William Rose
William Rose le 20 Avr 2023
@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?

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by