Different limits of function sequence

조회 수: 6 (최근 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