Hier mijn code :
Code: Selecteer alles
function benadering = oefening3(k)
theta = linspace(1, 2*pi, k+1);
vierkant = f_theta(theta);
z = zeros(1, k+1);
som = zeros(1,k+1);
coef = zeros(1,k+1);
for j = 1 : k + 1
z(j) = (theta(j) - (theta(1) + theta(k+1))/2)/((theta(k + 1) - theta(1))/2);
end
for i = 1 : k + 1
if ((0 <= theta(i)) && (theta(i) < pi/4))
functie = @(theta) sqrt(1 + (tan(theta)).^2).*chebyshev(k,z)./sqrt(1 - theta.^2);
elseif ((3*pi/4 <= theta(i)) && (theta(i) < 5*pi/4))
functie = @(theta) sqrt(1 + (tan(theta)).^2).*chebyshev(k,z)./sqrt(1 - theta.^2);
elseif((7*pi/4 <= theta(i)) && (theta(i) <= 2*pi))
functie = @(theta) sqrt(1 + (tan(theta)).^2).*chebyshev(k,z)./sqrt(1 - theta.^2);
elseif ((pi/4 <= theta(i)) && (theta(i) < 3*pi/4))
functie = @(theta) sqrt(1 + (cot(theta)).^2).*chebyshev(k,z)./sqrt(1 - theta.^2);
elseif ((5*pi/4 <= theta(i)) && (theta(i) < 7*pi/4))
functie = @(theta) sqrt(1 + (cot(theta)).^2).*chebyshev(k,z)./sqrt(1 - theta.^2);
end
coef(i) = quad(functie, -1, 1);
end
for i = 1 : k + 1
som(i) = som(i) + coef(i).*chebyshev(i,theta(i));
end
benadering = coef(1)/2 + som(k+1);
De functie chebyshev die erin voorkomt is trouwens een functie die ik zelf geschreven heb die de k-de chebyshev van een interval z berekend. Hierin is niets fout want deze heb ik al meerdere keren succesvol gebruikt.