Different limits of function sequence

5 次查看(过去 30 天)
Andrei
Andrei 2023-10-25
评论: Andrei 2023-10-25
Write a function convergenceFunc(fn, f, a, b, n, convType) that takes as input arguments: a function fn(n,x), fn(n,x) = f_n(x) - and a function f considered as the limit of the sequence f_n(x) on [a,b] in the sense given by the string convType: it can be pointwise convergence, uniform convergence, mean-square convergence.
And at this point I am a bit puzzled, since I want to enter only fn(n,x) and write matlab function, whichtake fn and find limits in different senses according to convType. But I dont know what to chage in limit to obtain different funcions for different types of convergeance.
  5 个评论
Andrei
Andrei 2023-10-25
For some functions there is only one type of convergeance - then convType can return error in case when expression doesnt convege in sense of convType. Also inside function I will evaluate errors which depend on convType
Andrei
Andrei 2023-10-25
I have written my realization, but it is no automized
clc
clear
close all
a = 0;
b = 1;
n = 10;
fn = @(n, x) (2.*x.*n + (-1).^n.*x^2)./n;
f = @(x) 2.*x;
% Uniform Convergence
convergenceFunc(@(n, x) (2.*x.*n + ((-1).^n).*x.^2)./n , @(x) 2.*x, a, b, n, 'uniform');
% Mean Squared Convergence
convergenceFunc(@(n, x) (2.*x.*n + ((-1).^n).*x.^2)./n , @(x) 2.*x, a, b, n, 'mean_squared');
% Pointwise Convergence
convergenceFunc(@(n, x) (2.*x.*n + ((-1).^n).*x.^2)./n , @(x) 2.*x, a, b, n, 'pointwise');
function convergenceFunc(fn, f, a, b, n, convType)
x = linspace(a, b, 1000);
y_fn = zeros(1000, n);
y_f = f(x);
figure
for i = 1:n
y_fn(:, i) = fn(i, x);
if strcmp(convType, 'uniform')
diff_metric = max(abs(y_fn(:, i) - y_f));
title_str = 'Uniform Convergence';
elseif strcmp(convType, 'mean_squared')
diff_metric = sqrt(mean((y_fn(:, i) - y_f).^2));
title_str = 'Mean Squared Convergence';
elseif strcmp(convType, 'pointwise')
diff_metric = NaN;
title_str = 'Pointwise Convergence';
end
plot(x, y_fn(:, i), 'b', x, y_f, 'r');
title(title_str);
legend(['f_', num2str(i)], 'f');
xlabel('x');
ylabel('y');
title(['Metric: ', num2str(diff_metric)]);
drawnow;
hold on
pause(0.5);
end
end

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by