Trabb Pardo–Knuth algorithm: Difference between revisions

m
imported>Arakov
m (→‎{{header|Wren}}: Minor tidy)
 
(2 intermediate revisions by 2 users not shown)
Line 1,594:
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
print "Please enter 11 numbers :"
n[] = number strsplit input " "
print ""
print "Evaluating f(x) = |x|^0.5 + 5x^3 for the given inputs :"
for i = len n[] downto 1
r = sqrt abs n[i] + 5 * pow n[i] 3
write "f(" & n[i] & ") = "
if r > 400
print "Overflow!"
else
print r
.
.
# without this section, the input is interactive
input_data
10 -1 1 2 3 4 4.3 4.31 4.32 4.32 4.29
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 2,925 ⟶ 2,945:
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>
 
Line 4,313 ⟶ 4,371:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
import "./fmt" for Fmt
 
var f = Fn.new { |x| x.abs.sqrt + 5*x*x*x }
9,476

edits