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