Trabb Pardo–Knuth algorithm: Difference between revisions

Add MATLAB implementation
imported>Arakov
(Add MATLAB implementation)
Line 2,925:
f[1.18367]= 9.38004
f[0.470145]= 1.20527
</pre>
 
=={{header|MATLAB}}==
{{trans|Julia}}
<syntaxhighlight lang="MATLAB}}">
clear all;close all;clc;
 
% Define the function f(x)
f = @(x) sqrt(abs(x)) + 5 * x^3;
 
% Read a line of input, split it into elements, convert to numbers
inputLine = input('', 's');
numbers = str2double(strsplit(inputLine));
 
% Process each number in reverse order
for i = length(numbers):-1:1
value = f(numbers(i));
if value > 400
fprintf('%g: TOO LARGE\n', numbers(i));
else
fprintf('%g: %g\n', numbers(i), value);
end
end
</syntaxhighlight>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11
11: TOO LARGE
10: TOO LARGE
9: TOO LARGE
8: TOO LARGE
7: TOO LARGE
6: TOO LARGE
5: TOO LARGE
4: 322
3: 136.732
2: 41.4142
1: 6
</pre>
 
337

edits