michjoh

20 Reputation

3 Badges

9 years, 264 days

MaplePrimes Activity


These are questions asked by michjoh

Working on a code to create random lines. Here is the code: 

M:=1; N:=1500; R3:=rand(1..3): # M=lines, N=steps

for i from 1 to M do
X[i,0]:=0;
Y[i,0]:=0;
   for j from 0 to N do
   if j=1 then X[i,1]:=1; Y[i,1]:=0;
    elif j>1 then
      r:=R3();
        if r=1 then X[i,j]:=2*X[i,j-1]-X[i,j-2]; Y[i,j]:=2*Y[i,j-1]-Y[i,j-2]
        elif r=2 then X[i,j]:=X[i,j-1]+Y[i,j-1]-Y[i,j-2]; Y[i,j]:=Y[i,j-1]-X[i,j-1]+X[i,j-2];
        elif r=3 then X[i,j]:=X[i,j-1]-Y[i,j-1]+Y[i,j-2]; Y[i,j]:=Y[i,j-1]+X[i,j-1]-X[i,j-2];
      end if;
    end if;
   R[i,j]:=[X[i,j],Y[i,j]];
   K[i,j]:=[X[i,j],Y[i,j]];
  end do:
end do:

Now the code works fine. But I don't want the lines to cross its own path. I want it to stop if R[i,j]=R[i,k] for any 0<k<i-2 for j=0..N. What I have so far is:

for i from 1 to M do
  for j from 1 to 40 do
    R[i,j];
    for k from 1 to j-2 do
     if R[i,j]=K[i,k] then x:=j; print(b[i]=j); break; end if;
     L[i,j]:=R[i,j];
     end do;
   end do;
end do;

Now it works aswell, but it doesn't stop when it hits the crossing point. I want it to stop so i get one b[i]=j per M. So I need it to break two for loops so that it goes through i M times and stops everytime it reaches a crossing point

Hi,

I'm trying to create a code that allows me to model a random walk for 50 people. I'm using r[i]= {X[i],Y[i]} where i is the number of steps and r[i] the position in the i-th term.

I have created three possibilities:
2r[i]-r[i-1] - go stright forward

{x[i]+y[i]-y[i-1],y[i]-x[i]+x[i-1]} - turn right

{x[i]-y[i]+y[i-1],y[i]+x[i]-x[i-1]} - turn left

The first step I want them to make is to point (1,0) and from there I want them to take 1500 random steps.

M:=50; N:=1500; R3:=rand(1..3):

for i from 1 to M do
X[i,0]:=0;
Y[i,0]:=0;
R[i,0]:=[X[i,0],Y[i,0]];
for j from 1 to N do
R[i,j]:=[X[i,j],Y[i,j]];
if j=1 then X[i,1]:=1; Y[i,1]:=0;
elif j>1 then
r:=R3();
if r=1 then R[i,j]:=2*R[i,j]-[R[i,j-1];
elif r=2 then R[i,j]:=[X[i,j-1]+Y[i,j-1]-Y[i,j-2],Y[i,j-1]-X[i,j-1]+X[i,j-2]];
elif r=3 then R[i,j]:=[X[i,j-1]-Y[i,j-1]+Y[i,j-2],Y[i,j-1]+X[i,j-1]-X[i,j-2]];
end if;
end if;
end do:
end do:

 

The first and second step works, but from there it seems Maple is having trouble getting the correct digigts, because the formulas coming out are correct.

I have tried putting in different types of X, Y and R reads, but have gotten stuck. If someone could help me spot what this code is missing I would be very gratefull. I think Maple is just missing a way of reading X and Y but i might be wrong.

Hi, I am working on an assignment and I am having difficulties with this Eurler method since I am working with vector.

The assignment:

If the aircraft's engine transmits power P to the air, the force of the propellar, Fp, satisfies P=Fpv. Since the force Fp acts in the direction of motion, it can be written in vector form as: (what I have so far)


with(linalg);

v:=Vector(2,1,[vx,vy]); velocity vector

nu:=v->Norm(Vector(v),2); (length of v)

Fd:=-1/2*C*rho*A*nu*v # air resistance

Fl:=1/2*Cl*rho*A*nu*v # liftforce in y direction here v=[-vy,vx]

Fp:=(P/nu^2)*v^2 # power from aircraft

All this adds up to:

F_T:=v->Vector(evalm(Fp/nu(v)^2*v+Fd*nu(v)*v+Fl*nu(v)*zip((x,y)->x*y,v([2,1]),Vector([-1,1]))+Vector(2,1,[0,-m*g]))); # I have tried it and it works

 

so up til here I am good. It is this next part that I can't seam to get.

Write a routine which uses Euler's method to solve the equation of motion numerically for velocity v(t):

m*dv/dt=F_T(v)

Test the program by trying a plane with intitial velocity [v0,0] such that it maintains this speed when the engines power is P=P0

We have been given an Esolve we can use:

Esolve:=proc(f::procedure,h,x0,y0,N::integer) # Calculates y(x0+n*h) for n=1..N given y0=y(x0) and f(x,y)

local n,y,x;

y[0]:=y0; # Start Value
x:=x0;

for n from 1 to N do
y[n]:= y[n-1]+h*f(y[n-1],x); # Euler's formula
x:=x+h; # Next x
end do;

y;

end proc;

 

If anyone could help me understand how it works and how to get this to work with vectors I would be very gratefull.

Page 1 of 1