- #1

- 472

- 14

Matlab:

```
01. nuclei=zeros(1,100);
02. t=nuclei;
03. nuclei(1)=input('Enter initial number of nuclei: ');
04. t(1)=0;
05. t_c=input('Enter time constant: ');
06. dt=input('Time step: ');
07. for i=1:99
08. nuclei(i+1)=nuclei(i)-(nuclei(i)/t_c)*dt;
09. t(i+1)=t(i)+dt;
10. end
11. plot(t,nuclei,'-ok','MarkerFaceColor','k')
12. xlabel('Number of Nuclei','FontWeight','bold')
13. ylabel('time(s)','FontWeight','bold')
14. title('Radioactive Decay Number of nuclei versus time')
15. str1=['Time Constant= ' num2str(t_c) ' s '];
16. str2=['Time Step= ' num2str(dt) ' s'];
17. text(t(50),nuclei(10),str1,'FontWeight','bold','FontSize',14)
18. text(t(50),nuclei(20),str2,'FontWeight','bold','FontSize',14)
```

02. I don't really know. perhaps we are defining a matrix t as well? Removing this line doesn't change the graph either. perhaps just for efficiency.

03. in the first position of the nuclei matrix, enter the number of nuclei.

04. in matrix t, position 1 has a value of 0? Not entirely sure though. I think this is another line that I commented out and it had no effect. the textbook mentions in its true basic sudo code that t(1)=0 as a convention for Euler's method???

05. entering the time constant

06. entering the time step

07. for i=1:99. I understand a for loop. but I think the code should be I=1:numberOfNuclei-1

I don't know why it is numberofNuclei-1, but the sudo code in book implies it. it says:

I can't figure out what size(t) is from what is written in the book. I am thinking that it is possible that size is a function (or sudo function?) in true basic that returns the size of the array that is in parenthesis. so size(t) would return 100 since 100 is the size of the array, t?for i=1 to size(t)-1

if this is true, I don't understand it. because in both this code and the sudo code, t is given a permanent size of 100. It happens that 100 is the number of nuclei the author plugs into this function. but what if I wanted to do 200 nuclei? the size of the arrays: t and nuclei are still 100. and so the for loop will still only go from 1->99?