Home www.visualprog.cz |
Send us your question |
Sine function with/without sin(x) |
---|
DECLARE @x FLOAT = 0
DECLARE @a FLOAT WHILE @x < 1.57 BEGIN SELECT @a = @x * ( 120 - @x * @x * ( 20 + @x * @x ) ) / 120 SELECT @x AS x, Sin(@x) AS [sin], @a AS a, @a - Sin(@x) AS rozdil SELECT @x = @x + 0.1 END go DECLARE @x FLOAT = 0 DECLARE @a FLOAT DECLARE @b FLOAT DECLARE @vysl FLOAT WHILE @x < 1.57 BEGIN SELECT @a = @x, @b = @x * @x SELECT @vysl = 42 - @b SELECT @vysl = 840 - @b * @vysl SELECT @vysl = 5040 - @b * @vysl SELECT @vysl = @a * @vysl / 5040 SELECT @x AS x, Sin(@x) AS [sin], @vysl AS vysl, @vysl - Sin(@x) AS rozdilX SELECT @x = @x + 0.1 END |
Hyperbolic function |
-- http://graph-plotter.cours-de-math.eu/
-- -500/(x-100)+1.8 DECLARE @Ax FLOAT=0, @Ay FLOAT, @Bx FLOAT, @By FLOAT, @Cx FLOAT, @Cy FLOAT SELECT @Ay = 2 SELECT @Bx = 7, @By = 3 SELECT @Cx = 8, @Cy = 6 ---------------------------------------------------------------------------- DECLARE @p FLOAT, @q FLOAT, @r FLOAT SELECT @q = @Bx * ( @Cy - @Ay ) + @Cx * ( @Ay - @By ) SELECT @q = @Cx * @Bx * ( @Cy - @By ) / @q SELECT @r = @Bx * @By - @q * ( @By - @Ay ) SELECT @r = @r / @Bx SELECT @p = ( @r - @Ay ) * @q ---------------------------------------------------------------------------- PRINT 'A[' + Cast(@Ax AS VARCHAR(50)) + ', ' + Cast(@Ay AS VARCHAR(50)) + '] ' + 'B[' + Cast(@Bx AS VARCHAR(50)) + ', ' + Cast(@By AS VARCHAR(50)) + '] ' + 'B[' + Cast(@Cx AS VARCHAR(50)) + ', ' + Cast(@Cy AS VARCHAR(50)) + ']' PRINT '--------------------------------------------------------------------' PRINT 'f(x) = ' + Cast(@p AS VARCHAR(50)) + '/(x-' + Cast(@q AS VARCHAR(50)) + ')+' + Cast(@r AS VARCHAR(50)) PRINT '--------------------------------------------------------------------' DECLARE @x FLOAT = 0 WHILE @x < 11 BEGIN PRINT '[' + Cast(@x AS VARCHAR(50)) + ', ' + Cast(@p / (@x - @q) + @r AS VARCHAR(50)) + ']' SELECT @x = @x + 1 END |
Line to parabola function |
DECLARE @Ax FLOAT=0,
@Ay FLOAT, @Bx FLOAT, @By FLOAT, @Cx FLOAT, @Cy FLOAT SELECT @Ay = 2 SELECT @Bx = 5, @By = 3 SELECT @Cx = 7, @Cy = 4 ---------------------------------------------------------------------------- DECLARE @k FLOAT, @q FLOAT, @m FLOAT, @n FLOAT, @p FLOAT, @c1 FLOAT SELECT @k = ( @By - @Ay ) / @Bx SELECT @q = @Ay SELECT @c1 = ( @By - @Ay ) / ( @Bx - @Ax ) SELECT @n = @c1 * ( @Cx - @Bx ) + @By - @Cy SELECT @n = ( @c1 * ( @Cx * @Cx - @Bx * @Bx ) / 2 + @Bx * ( @By - @Cy ) ) / @n SELECT @p = @By - @c1 * ( @Bx - @n ) / 2 SELECT @m = @c1 / ( 2 * ( @Bx - @n ) ) ---------------------------------------------------------------------------- PRINT 'A[' + Cast(@Ax AS VARCHAR(50)) + ', ' + Cast(@Ay AS VARCHAR(50)) + '] ' + 'B[' + Cast(@Bx AS VARCHAR(50)) + ', ' + Cast(@By AS VARCHAR(50)) + '] ' + 'B[' + Cast(@Cx AS VARCHAR(50)) + ', ' + Cast(@Cy AS VARCHAR(50)) + ']' PRINT '--------------------------------------------------------------------' PRINT 'f1(x) = ' + Cast(@k AS VARCHAR(50)) + ' * x + ' + Cast(@q AS VARCHAR(50)) PRINT 'f2(x) = ' + Cast(@m AS VARCHAR(50)) + ' * (x - ' + Cast(@n AS VARCHAR(50)) + ')^2 +' + Cast(@p AS VARCHAR(50)) PRINT 'fc(x) = (' + Cast(@k AS VARCHAR(50)) + ' * x + ' + Cast(@q AS VARCHAR(50)) + ')*((1-sig(x-' + Cast(@Bx AS VARCHAR(50)) + '))/2) + (' + Cast(@m AS VARCHAR(50)) + ' * (x - ' + Cast(@n AS VARCHAR(50)) + ')^2 +' + Cast(@p AS VARCHAR(50)) + ')*((1+sig(x-' + Cast(@Bx AS VARCHAR(50)) + '))/2)' --(1+0.25*x)*((1-sig(x-4))/2) + (0.125*x*x)*((1+sig(x-4))/2) PRINT '--------------------------------------------------------------------' DECLARE @x FLOAT = 0 WHILE @x < 11 BEGIN PRINT '[' + Cast(@x AS VARCHAR(50)) + ', ' + Cast(@k * @x + @q AS VARCHAR(50)) + ']' + ' [' + Cast(@x AS VARCHAR(50)) + ', ' + Cast(@m * (@x - @n) * (@x - @n) + @p AS VARCHAR(50)) + ']' SELECT @x = @x + 1 END |