Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

Let t be the angle that the vector makes relative to the positive x axis.  Let L be the vector's length.  Then the vector is given by

v := L*<cos(t), sin(t)>;

 

In answering your previous questions, Kitonum has shown you the proper syntax for defining position vectors.  Let's call them r1 and r2 in this case.  You need to do:
r1 := t -> 2*t^2*_i+16*_j+(10*t-12)*_k;
r2 := t -> (20-6*t)*_i+4*t^2*_j+2*t^2*_k;

Then you may verify that r1(2) and r2(2) are equal, that is, the airplanes collide at t=2.

The velocities are the derivatives of the position vectors.  They are computed via:

v1 := D(r1);
v2 := D(r2);

The velocities at the time of collision are given by v1(2) and v2(2).  You
should be able to calculate the angle between those vectors.

Additionally:

  1.  Heed rlopez's advice on the proper use of "evaluate" versus "solve".
  2.  You will receive better help if instead of posting code fragments, you upload a complete worksheet.  In the window where you edit your message before sending, observe the big fat green arrow.  Click on it to upload worksheet.

 

Consider the functions "`w__i`(x,y), i=1,2," defined for all x, y, and let
    "`D__i`={(x,y) : `w__i`(x,y)>0 }".

We say that the function w__i characterizes the domain D__i.  One can then verify that

• 

the function w__1+w__2+sqrt(w__1^2+w__2^2) characterizes the domain `union`(D__1, D__2)

• 

the function w__1+w__2-sqrt(w__1^2+w__2^2)characterizes the domain `intersect`(D__1, `D__2.`)

This idea was introduced/popularized by Rvachev; see, e.g.,

http://appliedmechanicsreviews.asmedigitalcollection.asme.org/article.aspx?articleid=1395415

 

This enables us to build a characterizing function for a complicated domain by splitting the domain
into simpler domains. Here I illustrate the method by creating the 8-shaped domain seen at the end of
this worksheet.

 

restart;

A function which is positive on .25 < abs(r) and abs(r) < 1 and nonpositive otherwise:

R := -(r^2-1^2)*(r^2-0.25^2);

-(r^2-1)*(r^2-0.625e-1)

plot(R, r=-2..2, view=-0.5..0.5);

Function of x, yobtained by rotating the graph of R about the vertical axis:

w1 := subs(r=x^2+y^2, R);

-((x^2+y^2)^2-1)*((x^2+y^2)^2-0.625e-1)

w1 characterizes one of the two loops of the eight-shaped figure:

plot3d(w1, x=-2..2, y=-2..2, view=0..0.2);

Translate w1 in the y direction to obtain the characterizing function of the eight-shape's other loop:

w2 := subs(y=y-1.8, w1);

-((x^2+(y-1.8)^2)^2-1)*((x^2+(y-1.8)^2)^2-0.625e-1)

The function w1 + w2 + sqrt(w1^2 + w2^2) is positive where one or both of w1 and w2 are positive,
and nonpositive otherwise.

By taking the max(0, ...) we replace the negative parts by zero:

f := max(0, w1 + w2 + sqrt(w1^2+w2^2));

max(0, -((x^2+y^2)^2-1)*((x^2+y^2)^2-0.625e-1)-((x^2+(y-1.8)^2)^2-1)*((x^2+(y-1.8)^2)^2-0.625e-1)+(((x^2+y^2)^2-1)^2*((x^2+y^2)^2-0.625e-1)^2+((x^2+(y-1.8)^2)^2-1)^2*((x^2+(y-1.8)^2)^2-0.625e-1)^2)^(1/2))

Here is what f  looks like:

plot3d(f, x=-2..2, y=-2..4);

The function g is 1 where f is positive, and zero otherwise:

g := piecewise(f > 0, 1, 0);

g := piecewise(0 < max(0, -((x^2+y^2)^2-1)*((x^2+y^2)^2-0.625e-1)-((x^2+(y-1.8)^2)^2-1)*((x^2+(y-1.8)^2)^2-0.625e-1)+sqrt(((x^2+y^2)^2-1)^2*((x^2+y^2)^2-0.625e-1)^2+((x^2+(y-1.8)^2)^2-1)^2*((x^2+(y-1.8)^2)^2-0.625e-1)^2)), 1, 0)

Here is what g looks like:

plot3d(g, x=-1.4..1.4, y=-1.4..3.1, grid=[200,200],
  style=surface, color=gold, scaling=constrained,
  orientation=[-135,-60,180], axes=none);

Download mw.mw

I have no idea what your code is meant to plot, but if you wish to shift the origin of an existing plot to x=1, y=2, here is how:
newplot := plottools:-translate(oldplot,1,2);

 

I don't know how to do this in Maple, but it is very easy to solve by hand.


Integrating the differential equation diff(u(x, z, t), z)+C = 0 we obtain u(x, z, t) = -C*z+f(x, t),

where f(x, t) is an arbitrary function.  In view of this, the condition u(x, h(x, t), t) = 0 takes the form

-C*h(x, t)+f(x, t) = 0, and therefore f(x, t) = C*h(x, t). Plugging this back into the previous

expression for u we arrive at the solution "u(x,z,t)=-C*z+C*h(x,t)."

In line 13 from the bottom, delete the extra "end if".

My interpretation of the problem's statement is different from acer's and kitonum's.  I view the first equation as defining γ as the root xx of the equation on the right-hand side. Similarly, the second equation defines ψ as the root xx of the equation on the right-hand side.  With that in mind, here is how to proceed.

restart;

local gamma;

eq1 := gamma*sinh(gamma)+xi*psi*cosh(gamma) = 0;

gamma*sinh(gamma)+xi*psi*cosh(gamma) = 0

eq2 := -gamma^2+beta+sqrt(psi/w)*coth(sqrt(psi/w))-psi = 0;

-gamma^2+beta+(psi/w)^(1/2)*coth((psi/w)^(1/2))-psi = 0

In eq2 we see that we need psi/w >= 0if we are to have real solutions.

From eq1 we see that xi*psi = -gamma*tanh(gamma),  that is,"psi/(w)= -1/(xi*w)*gamma*tanh(gamma)." 

But gamma*tanh(gamma) >= 0, therefore psi/w >= 0 if and only if  xi and w have opposite signs.

params := xi=-1, w=1, beta=2;

xi = -1, w = 1, beta = 2

fsolve(eval({eq1,eq2}, {params}));

{gamma = 1.449541816, psi = 1.298212894}

Download mw.mw

You have a set of equation SysEq which are linear in the variables dq.  The coefficient matrix is obtained through
J := LinearAlgebra:-GenerateMatrix(SysEq, dq)[1];

In your case J is an 8x11 matrix.  To display it, do:
evalm(J);

 

@assma Here is the code to do that calculation.  I assume that your 6.28 is actually meant to be 2π.  Change it to anything else as needed.

The 2D version

err2 := abs(wr(x,y) - w3(x,y));

range2 := x=0..2*Pi, y=0..2*Pi;

First, be sure that this one works correctly:

maximize(err2, range2);

Only then measure the usage statistics:

CodeTools:-Usage(maximize(err2, range2));

 

The 3D version

err3 := abs(wr(x,y,z) - w3(x,y,z));

range3 := x=0..2*Pi, y=0..2*Pi, z=0..2*Pi;

maximize(err3, range3);

CodeTools:-Usage(maximize(err3, range3));

 

Download mw.mw

 

restart;

with(Statistics):

pts := [[0, 0], [1, 13], [2, 21], [6, 45], [12, 54], [15, 77]];

[[0, 0], [1, 13], [2, 21], [6, 45], [12, 54], [15, 77]]

The equation of the straight line that goes through the point (2,21) is  y = 21+a*(x-2),

that is, y = a*x-2*a+21. The LinearFit function does not accept a model involving an additive
constant
such as the 21 above, but that's alright.  We subtract 21 from the data, fit with the model

y = a*x-2*a, and then add 21 to the result.

pts1 := (x->x[1])~(pts);

[0, 1, 2, 6, 12, 15]

pts2 := (x->x[2]-21)~(pts);  # note the subtracted 21

[-21, -8, 0, 24, 33, 56]

L := LinearFit(a*x-2*a, pts1, pts2, x) + 21;  # note the added 21

HFloat(4.151724137931035)*x+HFloat(12.69655172413793)

Let's verify that L passes through (2,21):

eval(L, x=2);

HFloat(21.0)

plot([pts, L], x=0..15);

Download linearfit.mw

An object of the form [u1, u2, ..., un] is called a list in Maple. If that list is named X, then X[i] is the ith entry of that list. Each of the ui can itself be a list. If every ui is a list, then we say X is a list of lists. In that case the notation X[i][j] indicates the jth element of the ith list in X.

The argument J of your proc is expected to be a list of list.

  • The first line of the proc creates a list L from the list J as follows. Let's say the ith entry of L is [a,b,c]. Then the ith entry of L is the two-element list
        [a, (b+c*I)/a + 50*(1+I)/abs(J[1][2])]
    where I is Maple's notation for sqrt(-1), and abs() is the absolute value.
    Note: You would want J[1][2] to be nonzero, otherwise you will be dividing by zero.  In the example in the last line of your post is J[1][2] zero.  That's bad.
  • The second line of the proc defines a vector R whose ith entry equals the ith entry in L.
  • The next line says that:
        T := abs(L[1][3]);
        r := L[1][4];
    But L[1][4]  makes no sense since it attempts to pick the 4th entry of the list L[1] which is a list of two entries; there is no 4th entry.  Check for typos.

The rest of the code should be self-evident.

 

In addition to the ways pointed out by Robert Lopez, here are four other methods to calculate the dot product without complex conjugation:

  1.  LinearAlgebra:-DotProduct(<a,b>, <c,d>, conjugate=false);
  2. LinearAlgebra:-DotProduct(<a,b>, <c,d>) assuming real;
  3. <a,b>^%T . <c,d>;
  4. <a,b>^+ . <c,d>;

My preferred method is #4 since it requires the least amount of typing.

 

@Earl If all you want is the final graphics that you have shown in your worksheet, then it can be done through a direct evaluation of parameter ranges.  This produces better-looking graphics, without the need for "cheating" with a hi-res grid.

Here are the details: mw2.mw
Edit: removed a couple of lines of unused code from an earlier version

restart;

with(LinearAlgebra):

Example 1: We have two equations in three unknowns:

eqns :=
   1*x + 2*y + 3*z = 4,
   5*x + 6*y + 7*z = 8;

x+2*y+3*z = 4, 5*x+6*y+7*z = 8

The augmented matrix of our system of equations:

M := GenerateMatrix({eqns}, {x,y,z}, augmented);

_rtable[18446884503773816462]

Here is the solution, expressed as the parametric equations of a line in 3D:

<x, y, z> =~ LinearSolve(M, free=t);

_rtable[18446884503773811046]

Example 2:  The equations are expressed as Ax=B, where A is an `&x`(m, n) matrix and

and B is an m-vector:

m, n := 3, 5;

3, 5

A := RandomMatrix(m,n);

_rtable[18446884503773806830]

B := RandomVector(m);

_rtable[18446884503773809230]

The augmented matrix:

M := < A | B >;

_rtable[18446884503773810190]

Here is the solution -- an afine manifold in R^n:

<(x[i] $i=1..n)> =~ LinearSolve(M, free=t);

_rtable[18446884503773805494]

Are you sure that's Maple?  To me it looks like a mupad notebook.

How do I know that?

Rename Bugged.mw to Bugged.mw.zip , unzip it, then examine the contents.

 

 

 

First 38 39 40 41 42 43 44 Last Page 40 of 58