Items tagged with code code Tagged Items Feed

I accidentally came across a nice Mma animation. Unfortunately, I am able to present only few frames of it in MaplePrimes. See two inconsecutive frames below

 

I find this animation very deep. I don't remember something similar. It looks like an iterative
map shown in its dynamics. Not being an expert in Mathematica, I don't understand the machinery of the generating code.
n = 1000;
r := RandomInteger[{1, n}];
f := (#/(.01 + Sqrt[#.#])) & /@ (x[[#]] - x) &;
s := With[{r1 = r}, p[[r1]] = r; q[[r1]] = r];
x = RandomReal[{-1, 1}, {n, 2}];
{p, q} = RandomInteger[{1, n}, {2, n}];
Graphics[{PointSize[0.007], Dynamic[If[r < 100, s];
Point[x = 0.995 x + 0.02 f[p] - 0.01 f[q]]]}, PlotRange -> 2]
Here is its fragment translated into Maple:
>with(MmaTranslator):
>FromMma(" (#/(.01 + Sqrt[#.#])) & /@ (x[[#]] - x) &;");
map(unapply(_Z1/(0.1e-1+sqrt(_Z1 . _Z1)), _Z1), unapply(x(_Z1)-x, _Z1))
To my regret,
>FromMma(" n = 1000;
r := RandomInteger[{1, n}];
f := (#/(.01 + Sqrt[#.#])) & /@ (x[[#]] - x) &;
s := With[{r1 = r}, p[[r1]] = r; q[[r1]] = r];
x = RandomReal[{-1, 1}, {n, 2}];
{p, q} = RandomInteger[{1, n}, {2, n}];
Graphics[{PointSize[0.007], Dynamic[If[r < 100, s];
Point[x = 0.995 x + 0.02 f[p] - 0.01 f[q]]]}, PlotRange -> 2]");
Error, (in MmaTranslator:-FromMma) incorrect syntax (at position 11) in last character of "...0)
r"

Hello,

I have .mla. package and I would like to create the source code associated to this package.

In the past, you have also help me to obtain the source code of procedure of the module.

Here the post where Carl Love has helped me :

http://www.mapleprimes.com/questions/203676-Open-A-Maple-Package

How can I do to create the complete source code of package directly ?

Is there a direct way enabling to not have to read one procedure by one procedure but to obtain the code source for all the package ?

Thank you for your help

 

 

I should be able to use F3 to break into a multline nested loop and insert a new line of code, and then F4 to close it up again before execution.  The F4 works for closing things up.  But the F3 does NOT work.  Is this a known problem?  Is there another way to do it short of a lot of cutting and pasting?

Euler := proc (f::procedure, a, b, alpha, n::integer)
local w, h, i, xN, yN;
w := array(1 .. 2, 1 .. n+1);
h := (b-a)/n;
i := 1;
xN := a;
yN := alpha;
while i <= n+1 do
w[1, i] = xN;
w[2, i] = yN;
print*w[1, i]
yN = yN+h*f(yN, xN);
xN = xN+h;
i = i+1
end do;
print*w
end proc

using the code generator assistant I entered the following function

p := proc (z::(float[8]))

local a::integer, accm::(float[8]), k::integer, k1::(float[8]), c;
c := Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], order = C_order, datatype = float[8]);
k1 := 1;
c[1] := evalf(sqrt(2*Pi));
a := 12;
for k to a-1 do c[k+1] := evalf(exp(a-k)*(a-k)^(k-1/2)/k1); k1 := -k1*k end do;
accm := c[1];
for k to a-1 do accm := accm+evalf(c[k+1]/(z+k)) end do;
accm := accm*evalf(exp(-z-a)*(z+a)^(z+1/2));
return accm/z
end proc

the code-generated julia code follows

function input(z)
c = [0,0,0,0,0,0,0,0,0,0,0,0]
k1 = 1
c[0] = (sqrt(2 * pi))
a = 12
for k = 1:a - 1
c[k] = (exp(a - k) * (a - k) ^ (k - 1//2) / k1)
k1 = -k1 * k
accm = c[0]
for k = 1:a - 1
accm = accm + (c[k] / (z + k))
accm = accm * (exp(-z - a) * (z + a) ^ (z + 1//2))
return(accm / z)
end

two things are wrong

1: no end after loop end

2: array index starts at 0, it should be 1 and of course the array references should reflect that

 

btw, it would be nice to be able to enter code tags like [code] code here [/code]

I have a .mpl file containing some procedures and other code.
When I open the file, everything is placed in a single execution group
(I use 1D math, worksheet mode).

Is it possible to have distinct execution groups?
For example, after each two blank lines (or other separator) in the .mpl file.

The same question when using .txt files as Maple input (in this case the code being not executed).

Thank you.

I use Mathematica. This code finds integer points on the sphere

(x-2)^2 + (y-4)^2 + (c-6)^2 =15

and select two of them so that distance of two this points equal to 4.

ClearAll[a, b, r, c];
a = 2;
b = 4;
c = 6;
r = 15; ss =
Subsets[{x, y, z} /.
Solve[{(x \[Minus] a)^2 + (y \[Minus] b)^2 + (z \[Minus] c)^2 ==
r^2, x != a, y != b, z != c, x y z != 0}, {x, y, z},
Integers], {2}];
t = Select[ss, And @@ Unequal @@@ Subsets[Flatten[#], {2}] &];
Length[t]
Select[ss, Apply[EuclideanDistance, #] === 4 &]

 

and this code select four points on the shere so that none of three points make a right triangle

ClearAll[a, b, r, c];
a = 2;
b = 4;
c = 6;
r = 15;
ss = Subsets[{x, y, z} /.
Solve[{(x - a)^2 + (y - b)^2 + (z - c)^2 == r^2, x != a, y != b,
z != c, x y z != 0, x > y}, {x, y, z}, Integers], {4}];
nonright =
Pick[ss, (FreeQ[#, \[Pi]/2] &) /@ ({VectorAngle[#2 - #1, #3 - #1],
VectorAngle[#1 - #2, #3 - #2],
VectorAngle[#1 - #3, #2 - #3]} & @@@ ss)];
Select[nonright, (12 == Length[Union @@ #] &)]

 I am looking for a  procedure in Maple.  I have some problems with this sphere. For example:

Choose four points so that 12 coordinates difference and it makes a square.

Can your code improve with sphere?

Dear all;

 

Hello everybody, I need your help to dispaly some values obtained using my function f. When I run the code there is no results obtained. Many thanks.

restart:

# The vectors e(i) satify the folowing conditions
e(0)*e(1)=e(n-1) assuming  1<n;
e(0)*e(0)=e(2):
e(1)*e(1)=e(n-1) assuming  1<n: :
e(2)*e(1)=e(n) assuming  1<n:
#
for i from 1  to n-1 do
e(i)*e(0)=e(i+1);
end do:

# We define the function f
f:=e(0)->e(0)+(n-3)*e(1);
f:=e(1)->(n-2)*e(1);
for i from 2  to 3 do
f:=e(i)->(n+i-3)*e(i)+(i-1)*(n-3)*e(n-3+i);
end do:

for i from 4 to n do
f:=e(i)->(n+i-3)*e(i)
end do:

# We define the two vectors
x:=sum(alpha(k)*e(k),k=0..n);
y:=sum(beta(k)*e(k),k=0..n);

#Question : I would like to compute the following  but there is no display of the solution. 
(x*y);
f(x*y);
f(x);
f(y);
x*f(y);
f(x)*y;
f(x*y)- f(x)*y-x*f(y);

HAM for convective boundary layer flows? please share

can  we share code or exchange code?

email me : faisalbasir91@gmail.com/+60182236765

Hello,

I need to be able to find the difference between the ith+1 and the ith element of a sequence and store that difference in another list. My code so far doesn't seem to be able to do that. My code is below. Thank you in advance to anyone taking their time looking at this, any help is greatly appreciated!



Worksheet_Assignment_4_Ex_2_(v).mw

 

Kind regards,

Gambia Man

I'm trying to run c code generated from a simple MapleSim example (Spin Up Beam). To makes things even simpler, I set the input real expression to just time, and changed the input function in my c code to:

static void inpfn(double T, double *U)
{
U[0] = T;
}

I set all the state variables to 0 for the initial conditions. I ran the code and my output doesn't resemble the MapleSim output at all, and I'm getting errors. So my question is about the state variables, which I initially set to 0:

* State variable(s):
* x[ 0] = `Main.SpinUpBeam.FB3.uf1`(t)
* x[ 1] = diff(`Main.SpinUpBeam.FB3.uf1`(t),t)
* x[ 2] = `Main.SpinUpBeam.FB3.uf2`(t)
* x[ 3] = diff(`Main.SpinUpBeam.FB3.uf2`(t),t)
* x[ 4] = `Main.SpinUpBeam.FB3.vf1`(t)
* x[ 5] = diff(`Main.SpinUpBeam.FB3.vf1`(t),t)
* x[ 6] = `Main.SpinUpBeam.FB3.vf2`(t)
* x[ 7] = diff(`Main.SpinUpBeam.FB3.vf2`(t),t)

What do these represent for this flexible beam (FB3)? I.e. what is uf1, uf2, vf1, vf2? Should they be set to 0, or no?

Thanks.

The title pretty much says it, but I wrote a bunch of code that operates on a matrix of given size. Now I want to increment that size with a loop, how can I put a loop around all the code? It won't let me just copy paste it into my loop body for some reason. Thanks!

Social Golfer Problem

So we have 8 golfers : 2 golfers per group and 4 groups.Over several golfing days, how can they be arranged so no golfer plays with the same player twice.

turns out they can play for 7 days.

So my attempt in maple....golfing.mw

For 3 players per group and 4 groups this is the arrangement over 4 days:

(these was done in wolfram demonstrations project but the code appears to be obfuscated)

 Maple code when open saved maple sheet?

and keep it can run code and show latest result after open

i mean user can not extend or find code or display code in maple sheet , just can run result

Hi,

i have been looking to see if i could get the source code for some of the calculus functions in maple. So far, i have tried this

kernelopts(opaquemodules = false)

interface(verboseproc = 3)

print(DiffTutor)

which shows the result

module() ... end module

does anybody have any idea how i would:

1) get the full list of sub-procedures in the module

2) get the source code of any of the sub-procedures in the module?

Thanks in advance!!

1 2 3 4 5 6 7 Last Page 1 of 15