# S.O.S. Mathematics CyberBoard

Your Resource for mathematics help on the web!
 It is currently Sun, 19 May 2013 12:34:48 UTC

 All times are UTC [ DST ]

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Random walk with matlabPosted: Mon, 13 Feb 2012 01:41:45 UTC
 S.O.S. Oldtimer

Joined: Sat, 21 Jan 2012 03:59:22 UTC
Posts: 182
The question is : Suppose you want to know how often a single source of fungus will spread more than one foot from a fallen tree. You will be using a computer simulation to answer this question based on the random walk model of the tree fungus in the textbook.

this is code using matlab tha'ts given in the text

Subroutine:

function [y,concen]=fungi(n,t)
%n - number of fungi
%t- number of steps
%y - max distances in each step
%concen - density of points at given distance

m1(1,1:n)=1:n;
m2(1,1:n)=(1:n)*0
y(1)=0
for i=1:t
alfa=rand(1,n)*pi;
d=rand(1,n);
m1(i+1, 1:n)=m1(i, 1:n)+(d.*cos(alfa));
m2(i+1, 1:n)=m2(i, 1:n)+(d.*sin(alfa));
if any(m2(i+1,:)<0);
xx=find(m2(i+1,:)<0);
for j=1 :length(xx)
m2(i+1, xx(j))=-m2(i+1), xx(j));
end;
end;
y(i+1)=max(max(m2(i+1,:)),y(i));
end;
maxy=y(t+1);
deltay=maxy/(2*t);
pop=n;
pointotal=sum(sum(m2(1:t+1,:)<=maxy)));
%pointotal - all points
ilosc(1)=n/pointotal;
for i-1:2*t
total = sum(sum(m2(1:t+1,:)<=((i/(2*t))*maxy)));
concen(i+1)=total-pop;
concen(i+1)=concen(i+1)/pointotal;
pop=total;
end;
subplot(2,1,1);
plot([1,n],[0,0],'k','LineWidth',2);
%hold on
for i=1:length(m1(1,:))
plot(m1(:,i),m2(:,i),'-*','Color',[rand(1),rand(1),rand(1)]);
%hold on
end;
xlabel('X');
ylabel('Y');
subplot(2,1,2);
plot([0:deltay:maxy],concen);
xlabel('distance');
ylabel('density');
%hold off
pause(0.01);

Driver statements:
function y=calcul(n,t)
for j=1:t
for i=1:100
[yy,i]=fungi(n,j);
point(i)=yy(j+1);
end;
y(j)=sum(point)/100;
end;

As soon as i type function [y,concen]=fungi(n,t) it gives me this error:??? function [y,concen]=fungi(n,t)
|
Error: Function definitions are not permitted in this context.

I do not do any computer programming so i need some help on how to start this. Our teacher kinds just threw this at us. What valuse should n,t,y and concen be?

Top

 Post subject: Re: Random walk with matlabPosted: Sun, 18 Mar 2012 12:39:28 UTC
 Member

Joined: Fri, 21 Oct 2011 16:04:51 UTC
Posts: 11
[y,concen] are the values that will be returned to you after the calculations are complete. You need to input the parameters "n" and "t" only so you will call it by "fungi(n,t)". as for the values of "n" and "t" to input that is up to you but this should stop giving you that error.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC [ DST ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ High School and College Mathematics    Algebra    Geometry and Trigonometry    Calculus    Matrix Algebra    Differential Equations    Probability and Statistics    Proposed Problems Applications    Physics, Chemistry, Engineering, etc.    Computer Science    Math for Business and Economics Advanced Mathematics    Foundations    Algebra and Number Theory    Analysis and Topology    Applied Mathematics    Other Topics in Advanced Mathematics Other Topics    Administrator Announcements    Comments and Suggestions for S.O.S. Math    Posting Math Formulas with LaTeX    Miscellaneous