Maximizing value for an array with integral function.
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have 'time(t)' and 'acceleration(A)' values. t1 and t2 are the lower and upper limits, where (t2-t1 = 10).
f = max{((integration(A,t,t1,t2))^2.5) * (t2-t1)}
Please help me to put this function in my matlab code.
for t1=1:length(t)
for t2=t1:t1+10
f = (((int(A,t,t1,t2)))^2.5)*(t2-t1);
end
end
I am using this for loop, but getting error for integration.
채택된 답변
fmax = -Inf;
for t1=1:numel(t)-10
fmax = max((trapz(t(t1:t1+10),A(t1:t1+10)))^2.5*(t(t1+10)-t(t1)),fmax);
end
fmax
Best wishes
Torsten.
댓글 수: 8
Thank you for the reply Torsten. In my case, my limits "t1" and "t2" are also an array.
And also at the end it should give maximum value for paticular t1 and t2. 'fmax' at 't1=' , 't2='.
Thank you
f_max = -Inf;
fun = @(x)interp1(t,A,x);
for i = 1:numel(t1)
t1_actual = t1(i);
t2_actual = t2(i);
f_actual = (integral(fun,t1_actual,t2_actual))^2.5*(t2_actual-t1_actual);
if f_actual > f_max
t1_max = t1_actual;
t2_max = t2_actual;
f_max = f_actual;
end
end
t1_max
t2_max
f_max
Thanks for your reply,
In the below code "A" is an array as a function of "t".
I have problem in the line "f = max((trapz(t(t1,t2),A(t1,t2)))^2.5*(t2-t1));"
With A(t1,t2) I am getting error in the loop.
fmax = -Inf;
for i=1:25
for j=i+1:i+15
t1=t(i);
t2=t(j);
f = max((trapz(t(t1,t2),A(t1,t2)))^2.5*(t2-t1));
if f>fmax
t1_max=t1;
t2_max=t2;
f_max=f;
end
end
end
f_max
t1_max
t2_max
Thanks in advance
1. t is a one-dimensional array, but in the call to "trapz", you use it as a two-dimensional array (t(t1,t2)).
2. The call trapz(x,y) to "trapz" with only one value for x (namely t(t1,t2)) and one value for y (namely A(t1,t2)) does not make sense.
As far as I understand what you want:
You have two one-dimensional arrays: t and A(t).
Further, you have two one-dimensional arrays t_low and t_up and you want to find the index i such that
(integral_{t=t_low(i)}^{t=t_up(i)} A(t) dt)^2.5 * (t_up(i)-t_low(i))
is maximized.
Is this correct ?
Best wishes
Torsten.
Yes Torsen, exactly I am doing as you explained. "t" is an one dimensional array and I have to define "t_low" and "t_up" from "t" such that, to say "t_low = 1:100" and "t_up = t_low+1:115".
t_up ~ t_low <=15 (This is the maximum difference, so i created t(i) and t(j) loops to perform this)
And also A(t_up) and A(t_low) should be respective t_up and t_low values.
Thanks
Then what's wrong with the following code (assuming t is a 100 x 1 array with increasing t values and A is also 100 x 1):
f_max = -Inf;
for i = 1:85
f = (trapz(t(i:i+15),A(i:i+15)))^2.5*(t(i+15)-t(i))
if f > f_max
tlow_max = t(i);
tup_max = t(i+15);
f_max = f;
end
end
f_max
tlow_max
tup_max
Thank you Torsten. I understand now where I am doing mistake. Your suggestion helped a lot.
And one more thing in the result t(i) and t(i+15) is fixed to "t(i+15) - t(i) = 15".
But It can be any point between t(i+15) and t(i).
For example:
t_low = 7
t_up = 10
for f_max = 100
(because of this reason I introduced "i" and "j". As you said its two-dimensional array )
Thanks
f_max = -Inf;
for i = 1:85
for j = 1:15
f = (trapz(t(i:i+j),A(i:i+j)))^2.5*(t(i+j)-t(i))
if f > f_max
tlow_max = t(i);
tup_max = t(i+j);
f_max = f;
end
end
end
f_max
tlow_max
tup_max
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
