Temperature distribution in a thin square plate (iPad only)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Temperature distribution in a thin square plate (iPad only)

Post by Henko »

Code: Select all

' Temperature distribution in a thin, square plate.
' The plate is isolated on both sides, heat can only
' escape along the edges. A heat source warms up the plate
' in one point; this point may be repositioned by tapping
' somewhere on the plate. The strenght of the heat source
' can be regulated by the slider. The other slider sets the
' thermal conductivity, wich is a material property. The
' temperature distribution is shown in colors an in numbers.
' The "outside" temperature along the edges is fixed on 0 degrees.
'
graphics ! graphics clear .8,.8,.8
fill color .8,.8,.8 ! draw color 0,0,0
dim to(13,13), tn(13,13), q(12,12)
q_in=75 ! qx=4 ! qy=7 ! labda=0.1 ! cv=1 ! tmax=300
for i=1 to 11 ! for j=1 to 11
  to(i,j)=20 ! q(i,j)=20*cv
  next j ! next i
for i=0 to 12
  to(0,i)=0 ! to(12,i)=0 ! to(i,0)=0 ! to(i,12)=0
  next i
for i=0 to 10
  t=i/10 ! t_color(t) ! fill circle 85+60*i,750 size 15
  draw text n2a$(i*tmax/10,3,0) at 55+60*i,770
  next i
draw font size 16
slider "heat" value .5 at 70,820 hsize 630
draw text "heat source" at 330,815
draw text "zero" at 70,815 ! draw text "max" at 670,815
slider "cond" value .5 at 70,880 hsize 630
draw text "thermal conductivity" at 285,875
draw text "zero" at 70,875 ! draw text "max" at 670,875
draw color .3,.3,.3
loop:
disp(to)
for i=1 to 11 ! for j=1 to 11
  q(i,j) += labda*(to(i-1,j)+to(i+1,j)+to(i,j-1)+to(i,j+1)-4*to(i,j))
  next j ! next i
q(qx,qy) += q_in
for i=1 to 11 ! for j=1 to 11 ! to(i,j)=q(i,j)/cv ! next j ! next i
if slider_changed("heat") then q_in=150*slider_value("heat")
if slider_changed("cond") then labda=0.25*slider_value("cond")
get touch 0 as xt,yt
if xt>0 and xt>50 and xt<720 and yt>50 and yt<720 then
  qx=floor((xt+10)/60) ! qy=floor((yt+10)/60)
  end if
goto loop
end

def t_color(t)
if t<0 then t=0 ! if t>1 then t=1
if t<0.2 then
  r=0 ! g=0 ! b=5*t
  else
  if t<0.7 then
    r=2*(t-0.2) ! g=0 ! b=2*(0.7-t)
    else
    if t<0.9 then
      r=1 ! g=5*(t-0.7) ! b=0
      else
      r=1 ! g=1 ! b=10*(t-0.9)
      end if
    end if
  end if
fill color r,g,b
end def

def disp (t(,))
graphics lock
for i=1 to 11 ! for j=1 to 11
  x=50+60*(i-1) ! y=50+60*(j-1)
  t_color(t(i,j)/.tmax)! fill rect x,y to x+60,y+60
  draw text floor(t(i,j)) at x+10,y+20
  next j ! next i
for s=50 to 710 step 60 
  draw line 50,s to 710,s ! draw line s,50 to s,710
  next s
graphics unlock
end def

def n2a$(num,lang,dec)
b$="                  "
fac=10^dec
num$=floor(fac*num+.5)/fac
tot=lang-len(num$)
if tot<1 then tot=1
a$=substr$(b$,1,tot) & num$
n2a$=a$
end def
Last edited by Henko on Thu Mar 06, 2014 7:36 pm, edited 2 times in total.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Temperature distribution in a thin square plate (iPad on

Post by Mr. Kibernetik »

When running I have this error:
фотография.jpg
фотография.jpg (194.99 KiB) Viewed 4113 times

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Temperature distribution in a thin square plate (iPad on

Post by Henko »

A very strange thing (error) happens.
In the function n2a$(), the string constant b$ is initialized as b$=" ." ( a lot of spaces) after submitting, the statement reads b$="" ( all spaces disappeared), which leads to the error.
Even after editing, the added spaces disapear again,
I will try the spaces, and add a dot at the end.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Temperature distribution in a thin square plate (iPad on

Post by Henko »

In the previous message, the spaces are deleted again!!! :evil:
Adding a dot at the end of the string constant does not help.
In the edit mode, the spaces are shown again. I'm lost!

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Temperature distribution in a thin square plate (iPad on

Post by Mr. Kibernetik »

It seems that website converts a lot of spaces to one space in the text.
There are some variants how this can be avoided:
- Use "Code" marker to embed the text.

Code: Select all

B$="       "
- Attach text file instead of inserting text into message
- Use dropbox link to share code (maybe the best variant)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Temperature distribution in a thin square plate (iPad on

Post by Henko »

It's ok now. I placed the program between the "code" marks, which retains the spaces. Problem solved.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Temperature distribution in a thin square plate (iPad on

Post by Henko »

I am not a dropbox user, and will not be that in the future. If dropbox becomes the standard for exchange of smartbasic programs, i am gone, sorry

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Temperature distribution in a thin square plate (iPad on

Post by Mr. Kibernetik »

Henko wrote:I am not a dropbox user, and will not be that in the future. If dropbox becomes the standard for exchange of smartbasic programs, i am gone, sorry
Yes? What's wrong with it?
I thought that Dropbox is a very handy exchange and backup tool...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Temperature distribution in a thin square plate (iPad on

Post by Henko »

I tried to implement dropbox when Dutchman put his world chart in dropbox. It was a complete disaster, i have better things to do. So, apparently i am incapable to use dropbox and i will not lose time again with it. I understand however that dropbox can be an advantage when you have to share an app with multiple files. It's not for me, sorry

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Temperature distribution in a thin square plate (iPad on

Post by Mr. Kibernetik »

Actually I am eager to help you with Dropbox if you will have time/desire to set it up.

Post Reply