tsql – 如何使用T-SQL生成Mandelbrot?

学习一点T-sql,并认为一个有趣的练习就是用它生成一个Mandelbrot集.

原来已经有人(最近出现了).我会让其他人发布它作为答案,但我很好奇可以做出哪些优化.

或者,您将如何使代码更具可读性?

我将选择最可读(但相当紧凑)的版本作为已接受的答案(太糟糕了,我们还没有代表奖励!)除非有人真的带来了很好的优化.

奖金指向那些教我一些关于T-sql的答案.

-亚当

解决方法

Create PROCEDURE dbo.mandlebrot
@left float,@right float,@Top float,@Bottom float,@Res float,@MaxIterations Integer = 500
As
Set NoCount On

Declare @Grid Table (
    X float Not Null,Y float Not Null,InSet Bit
   Primary Key (X,Y))

Declare @Xo float,@Yo float,@Abs float
Declare @PtX Float,@PtY Float
Declare @Iteration Integer Set @Iteration = 0
Select @Xo = @Left,@Yo = @Bottom

While @Yo <= @Top Begin
    While @Xo <= @Right Begin
        Select @PtX = @Xo,@PtY = @Yo
        While @Iteration < @MaxIterations 
            And (Square(@PtX) + Square(@PtY)) < 4.0 Begin
            Select @PtX = Square(@PtX) - Square(@PtY) + @Xo,@PtY = 2* @PtX * @PtY + @Yo
            Select @Iteration,@PtX,@PtY
            Set @Iteration = @Iteration + 1
        End
        Insert @Grid(X,Y,InSet) 
        Values(@Xo,@Yo,Case 
            When @Iteration < @MaxIterations
                    Then 1 Else 0 End)
        Set @Xo = @Xo + @res
        Set @Iteration = 0
    End
    Select @Xo = @Left,@Yo = @Yo + @Res
End

Select * From @Grid

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...