Commit 25b67364 authored by Simon Breiter's avatar Simon Breiter

feat: update

parent 63c18f49
%%% NICHT VERALLGEMEINTERT, bearbeite "Parameter" direkt in Funktion
function [] = gauss_newton_num(ti, xi, f, ln, tol)
%GAUSS_NEWTON_NUM zur Lösung von nicht-linearen Ausgleichsproblemen
%
% ti = x Werte
% xi = y Werte
% f = Ansatzfunktion
% ln = Startvektor
% tol = Toleranz
ti = [];
xi = [];
f = @(x)x;
ln = [];
tol = 10^-5;
syms a b c d;
%f = matlabFunction(xi - (a .* exp(-b.*ti) .* sin(c.*ti + d)));
Df = matlabFunction(jacobian(f, [a, b, c, d]));
f_vec = @(l)f(l(1), l(2), l(3), l(4))';
Df_vec = @(l)Df(l(1), l(2), l(3), l(4));
%ln = [1 2 2 1]';
%tol = 10^-5;
err = tol + 1;
n = 0;
while err > tol
ATA = Df_vec(ln)' * Df_vec(ln);
ATy = -Df_vec(ln)' * f_vec(ln);
delta = ATA\ATy;
ln = ln + delta;
err = norm(delta, 2);
n = n + 1;
end
disp(ln);
disp(n);
% Gedaempftes Verfahren
%tol = 10^-5;
err = tol + 1;
ln = [1 2 2 1]';
n = 0;
while err > tol
ATA = Df_vec(ln)' * Df_vec(ln);
ATy = -Df_vec(ln)' * f_vec(ln);
delta = ATA\ATy;
p = 0;
for i = 10 : 0
if norm(f_vec(ln + delta./(2^i)), 2)^2 < norm(f_vec(ln), 2)^2
p = i
end
end
ln = ln + delta / 2^p;
err = norm(delta, 2);
n = n + 1;
end
disp(ln);
disp(n);
end
......@@ -33,7 +33,7 @@ function y = lagrange_num (x, xs, ys)
y = 0;
for i=1:n
y = y + (l(x, xs, n, i) * ys(i));
y = y + (l(x, xs, n, i) * ys(i))
end
end
......@@ -41,11 +41,11 @@ end
function p = l(x, xs, n, i)
%L Berechnet das i-te Lagrangepolynom vom Grad n
%
p = 1;
for j=1:n
if (j ~= i)
p = p * ((x - xs(j)) / (xs(i) - xs(j)));
disp(sprintf("Berechne das %i-te Lagrangepolynom vom Grad %i", i, n));
p = p * ((x - xs(j)) / (xs(i) - xs(j)))
end
end
......
function [yy] = spline_kubisch_num (x,y,xx)
% Berechnet die kubische Splinefunktion
% x muss aufsteigend sortiert sei
% Sample Call:
% x = [ 0 1 2 3 ]
% y = [ 2 1 2 2 ]
% xx = [ 0.5 0.8 1.1 2.2]
% interpolation_kubische_splinefunktion(x,y,xx)
n = length(x) - 1;
h = x(2:n+1) - x(1:n);
for j=2:n-2
z(j-1,1) = 3 * ((y(j+1)-y(j))/ h(j)) - 3 * ((y(j)-y(j-1))/h(j-1));
end
z(n-1,1) = 3 * ((y(n+1) - y(n)) / h(n)) - 3 * ((y(n)-y(n-1)) / h(n-1));
A = diag(h(2:n-1), 1) + diag(h(2:n-1), -1) + diag((h(1:n-1) + h(2:n)));
c = A\z;
c(2:n) = c(1:n-1);
c(1) = 0;
c(n+1) = 0;
c = c.';
d = (1 ./ (3*h)) .* (c(2:n+1) - c(1:n));
b = (y(2:n+1)-y(1:n))./h - (h/3) .* ((c(2:n+1)+2*c(1:n)));
for j=1:n
S = @(inp) y(j) + b(j)*(inp-x(j)) + c(j)*(inp-x(j)).^2 + d(j)*(inp-x(j)).^3;
r = find(x(j)<=xx & xx<=x(j+1));
yy(r) = S(xx(r));
end
end
function [ out ] = diff_forward ( f, x0, h )
function [ out ] = diff1_forward ( f, x0, h )
% DIFF_FORWARD Calculates forward differentiate
%
% f needs to be a symbolic equation
......
function [ int, remainder ] = divr( a, b )
%DIVR Division with remainder
%
% Params:
% a - Dividend
% b - Divisor
%
% Example use:
% [int, remainder] = divr(26,2)
int = fix(a/b);
remainder = rem(a,b);
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment