Skip to content

Instantly share code, notes, and snippets.

@Makazone
Created March 3, 2016 13:28
Show Gist options
  • Save Makazone/7286173e448dcaa7c9e1 to your computer and use it in GitHub Desktop.
Save Makazone/7286173e448dcaa7c9e1 to your computer and use it in GitHub Desktop.
function [y] = Fred_II_Rect(K,f,a,b,h)
x = a:h:b;
n = size(x,2);
wt = 1/2;
wj = 1;
A = zeros(n);
for i = 1:n
A(i,1)= h*wt*K(x(i),x(1));
for j=2:n-1
A(i,j)= h*gtwj*K(x(i),x(j));
end;
A(i,n)= h*wt*K(x(i),x(n));
A(i,i)= A(i,i)+ 1;
end;
B = zeros(n,1);
for j=1:n
B(j,1) = f(x(j));
end;
y = A\B;
close
all clear
all clc
format long;
N = 10;
h = 1 / N;
a = 0;
b = 1;
epsilon = 0.01;
K = @(x1,s)(x1 + s)*epsilon;
f = @(x1)x1;
y_approx1 = Fred_II_Rect(K,f,a,b,h);
epsilon = 0.005;
K = @(x1,s)(x1 + s)*epsilon;
y_approx2 = Fred_II_Rect(K,f,a,b,h);
hold on
plot(a:h:b, y_approx1);
plot(a:h:b, y_approx2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment