필터 지우기
필터 지우기

Evaluating a function in subitervales and comparing the function' values of each interval with te next interval

조회 수: 3 (최근 30일)
Hi. Can any one help me with the following please. let's say I have these values x=[ 2,3,-1,-4,2,-6,...1000], I need to subdevide these valuse into subintervals let's say each subinterval has 10 elements. Then I want to evaluate a function F(x) in each subinterval of x and compare the valuse of the function of the first interval with the function's value of the next interval and so on. Thankful your favor inadvanced.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 7일
The below is what you asked for. It seems unlikely to be what you want though.
x=[ 2,3,-1,-4,2,-6,...
1000];
num_x = length(x);
for xidx = 1 : num_x-1
first_x = x(xidx);
second_x = x(xidx+1);
sub_intervals = linspace(first_x, second_x, 10);
Fvals = zeros(1, 9);
for interval_idx = 1 : 9
this_subinterval = sub_intervals(interval_idx:interval_idx+1);
Fvals(interval_idx) = F(this_subinterval); %evaluate F on sub-interval ?
end
for interval_idx = 1 : 9
fprintf('major interval %g:%g, sub_interval %g:%g, value ', first_x, second_x, sub_intervals(interval_idx:interval_idx+1));
if Fvals(interval_idx) < F_vals(interval_idx+1)
fprintf('increases\n');
elseif Fvals(interval_idx) > F_vals(interval_idx+1)
fprintf('decreases\n);
elseif any(isnan(Fvals(interval_idx:interval_idx+1)))
fprintf('is indeterminate because of nan\n');
else
fprintf('stays the same');
end
end
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by