15 Reputation

One Badge

5 years, 119 days

MaplePrimes Activity

These are questions asked by MAJP


While working for an assignment I had to use a piecewise function which gives a result based on a randomly generated value. The following is a much simpler version of what I've been working on, but it gives the same error.

A random value is uniformly distributed between 0 and 100. The piecewise returns a 1 if the value is between 0 and 50 and it returns 2 if the value is between 50 and 100. As far as I understand this function should only ever give 1 or 2, never something else. However when I loop this a few times Maple regularly returns a 0, which doesn't make sense to me. I've printed the values that return a 0 but none of these should break the piecewise. Can someone please explain to me what's going wrong here and how to fix it?

My code:

restart; randir := piecewise(0 <= r1() and r1() < 50, 1, 50 <= r1() and r1() < 100, 2);
for i to 1000 do r1 := rand(0. .. 100.0); if randir = 0 then print(fail[i], r1()) end if end do;

I've included a failure check to see when and at what values it returns a 0, and as you can see it happens very often.

Hello, for an assignment I was given the task of iteratively calculating the water depth of a flow using Newton's method. For this I tried to create a procedure wich uses a number of input values. The code is listed below;


Newton := proc (n, y0, Q, b, m, k, S0) local A, P, Sf, y, F, dAdy, dPdy, Fdiff, i; global ylist; y[0] := y0; for i from 0 to n do A[i] := (b+m*y[i])*y[i]; P[i] := b+2*y[i]*sqrt(1+m^2); Sf[i] := Q*abs(Q)*P[i]^(4/3)/(k^2*A[i]^(10/3)); F[i] := S0/Sf[i]-1; dAdy[i] := b+2*m*y[1]; dPdy[i] := 2*sqrt(1+m^2); Fdiff := (2/3)*(F[i]-1)(5*dAdy[i]/A[i]-2*dPdy[i]/P[i]); y[i] := procname(evalf(y[i]-F[i](y[i])/Fdiff[i](y[i]))) end do; ylist := [seq(y[i], i = 0 .. n)]; return ylist end proc;

Newton(10, 1, 5, 12, 1, 30, 0.1e-4);
Error, (in Newton) invalid input: Newton uses a 2nd argument, y0, which is missing


As you can see, I get an error referring to the second argument y0, which is the starting value of the calculation. The error says the argument is missing, however it is right there in the brackets of the Newton procedure (along with the values of all other parameters). I have tried explicitly stating that y0:=1, and changing the name of the parameter, however that didn't help.

Am I missing something really simple, or is there something wrong with my code?

Thanks in advance.

Page 1 of 1