Begginer's Question about matrixes

조회 수: 1 (최근 30일)
Hugo Pontes
Hugo Pontes 2019년 11월 16일
댓글: dpb 2019년 11월 18일
For context I'm developing a basic car speed controller, in which I'm using the changes in altitude to determine a slope which will slow down the car. The controller will speed up the car when it is under the desired speed.
Anyway,
I have defined functions as matrix of (1,instances) many different different parameters, one of which is pressure
I am trying to define pressure as a function of altitude , with altitude being a matrix (1,n) of the following type:
altitude = [a,a,a,a,a,b,c,d,e,f,g,h,iiiiii] %a plane a slope and a plane again
and then I tried to calculate the pressure matrix as function of the altitude in each point as well as the difference in pressure between each step:
for s=1:it
press(1,s)=Ps*(1+(Lb/Ts)*altitude(1,s))^(-g0*M/R*Lb); %if youre not familiar with this formula, all the remaining paramters are constants
if s~=it
dp(1,s+1)=k1*(press(1,s+1))-k1*(press(1,s));% k is a gain parameter that I thought might fix this
end
end
but when I plot the pressure as function of altitude I get a downwards slope when I'm pretty sure I should be getting a quadratic
additionally the dp matrix should resemble a derivative of the pressure matrix and it is constant throughout time.
As I said I'm a begginer and perhaps this is not the best method for relating parameters with one another, so I'm open to suggestions.
Additionally I have no idea why it doesn't work so If somebody could clear it up for me I would appreciate it!
Thank you in advance
  댓글 수: 1
darova
darova 2019년 11월 16일
YOu should attach all constants/data and the code you used

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

채택된 답변

dpb
dpb 2019년 11월 16일
편집: dpb 2019년 11월 16일
press=Ps*(1+(Lb/Ts)*altitude).^(-g0*M/R*Lb);
dp=diff(press);
"The Matlab way" is to use the vectorized abilities built into operations. NB: the "dot" operator .^ for exponentiation of the vector elementwise instead of the matrix operation without the dot, ^
More than likely your altitude changes are simply not large enough for the power law to "kick in" numerically to see the nonlinearity obviously.
You could, of course, also write the analytic form for the derivative instead of using the differences and be more accurate and lest dependent upon "close enough" to estimate between observed values.
  댓글 수: 2
Hugo Pontes
Hugo Pontes 2019년 11월 17일
""The Matlab way" is to use the vectorized abilities built into operations. NB: the "dot" operator .^ for exponentiation of the vector elementwise instead of the matrix operation without the dot, ^"
That helped thanks!
"More than likely your altitude changes are simply not large enough for the power law to "kick in" numerically to see the nonlinearity obviously.
You could, of course, also write the analytic form for the derivative instead of using the differences and be more accurate and lest dependent upon "close enough" to estimate between observed values."
Is there a way to fix that? I was trying to avoid the derivative because it was such a simple controller design and I thought I could do it with differences between each step, but you're right derivative does seem to be the better option generally
I was unaware that the diff command existed, thanks for that as well!
dpb
dpb 2019년 11월 18일
Just write the analytic form for the derivative and code it.
BTW, the actual derivative needs to be diff(p)/da where da is the difference between the altitude points to normalize magnitude to the actual difference. gradient() also is there that does some internal weighting to midpoint of interval rather than the straight point difference that leaves the estimate one element shorter than the original in length.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by