25 lines
701 B
Plaintext
25 lines
701 B
Plaintext
'Freebasic .9
|
|
'Custom rounding
|
|
#define round(x,N) Rtrim(Rtrim(Left(Str((x)+(.5*Sgn((x)))/(10^(N))),Instr(Str((x)+(.5*Sgn((x)))/(10^(N))),".")+(N)),"0"),".")
|
|
|
|
#macro Euler(fn,_y,min,max,h,printoption)
|
|
Print "Step ";#h;":":Print
|
|
Print "time","Euler"," Analytic"
|
|
If printoption<>"print" Then Print "Data omitted ..."
|
|
Scope
|
|
Dim As Double temp=(min),y=(_y)
|
|
Do
|
|
If printoption="print" Then Print temp,round(y,3),20+80*Exp(-0.07*temp)
|
|
y=y+(h)*(fn)
|
|
temp=temp+(h)
|
|
Loop Until temp>(max)
|
|
Print"________________"
|
|
Print
|
|
End Scope
|
|
#endmacro
|
|
|
|
Euler(-.07*(y-20),100,0,100,2,"don't print")
|
|
Euler(-.07*(y-20),100,0,100,5,"print")
|
|
Euler(-.07*(y-20),100,0,100,10,"print")
|
|
Sleep
|