Skip to content

Commit

Permalink
ue5
Browse files Browse the repository at this point in the history
  • Loading branch information
joshinils committed Jun 26, 2019
1 parent 547e95f commit 06036db
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pa2
Submodule pa2 updated from 6d7b31 to 1d88ea
Binary file added uebungen/Num2_uebung5.pdf
Binary file not shown.
5 changes: 2 additions & 3 deletions uebungen/factorio/funcApprox/P.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
function [ p ] = P( b, xk, x )
b = b(1, :);
n = length(b);
n = size(b, 2);
p = b(1, n);
for k = (n-1) : -1 : 1
p = b(k) + p * (x - xk(k));
p = b(1, k) + p * (x - xk(k));
end
end

61 changes: 49 additions & 12 deletions uebungen/factorio/funcApprox/findBestKnot.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,58 @@
format compact;
format longg;

calcKnot1 = 1847.7;
calcKnot2 = 16350;
%% calculate initial nodes
% intervall in which to approximate
limit_start = 1;
limit_end = 3e5;
base = (limit_end)^(1/100); % of the log, meaning logb(limit_end) := 100
logb = @(x) log(x)/log(base);

KnotInterval = linspace(1, (calcKnot1+calcKnot2)/2);
best = 22.8643526713838;
window = .001;
KnotInterval = linspace(best*(1-window), best*(1+window));
n = 10; % amount of nodes

% tschebyschow nodes:
k = linspace(1, n, n)';
% according to: https://en.wikipedia.org/wiki/Chebyshev_nodes#Definition
x_i = sort( (limit_start + limit_end)/2 + (limit_end -limit_start)/2 * cos( (2*k -1)/(2*n)*pi ) )

minErr = 1e30;
minTry = 9;
maxTry = 10;

%%
for repeats = 1:1
for nodeNr = 1:n
window = 1;
nodeMinErr = 1e30;
for i=1:maxTry
window = window * .9;
KnotInterval = linspace(x_i(nodeNr)*(1-window), x_i(nodeNr)*(1+window), 10);

err = zeros(length(KnotInterval), 1);
for j=1:length(KnotInterval)
x_i(nodeNr) = KnotInterval(j);
err(j) = logbApproxNKnot(x_i, 1:n);
end
close;
plot(KnotInterval, err, '.r-');

[m,mi] = min(err);
fprintf('node%i, try%i, m%f, i%i\n', nodeNr, i, m, mi);

x_i(nodeNr) = KnotInterval(mi);
if minErr > m; minErr = m; end
if nodeMinErr > m; nodeMinErr = m; end
if nodeMinErr == minErr && i >= minTry
break;
end
end % i
fprintf('\n');
end % nodeNr
x_i
% pause
end % repeats

for i=1:length(KnotInterval)
err(i) = logbApproxNKnot(KnotInterval(i), 1);
end

plot(KnotInterval, err, '.r-');

[m,i] =min(err)

KnotInterval(i)

1 change: 0 additions & 1 deletion uebungen/factorio/funcApprox/logbApprox.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
tk = cos( (2*k -1)/(2*n)*pi )
% according to: https://en.wikipedia.org/wiki/Chebyshev_nodes#Definition
x_i = sort( (limit_start + limit_end)/2 + (limit_end -limit_start)/2 * cos( (2*k -1)/(2*n)*pi ) )
x_i(1)=22.8643526713838;
f_i = logb(x_i);

%% berechne koeffizienten
Expand Down

0 comments on commit 06036db

Please sign in to comment.