MaplePrimes Questions

How can I use fdiff within Optimization:-NLPSolve and get rid of this error?

Here is an example

restart:
with(Optimization):

# with exact gradient
obj := proc(v)
         10*v[1]^2 - 2*v[1]*v[2]^2 + v[2]^4 + 1 - 2*v[2] + v[2]^2
       end proc:

objgrad := proc(v, w)
        w[1] := 20*v[1] - 2*v[2]^2:
        w[2] := -4*v[1]*v[2] + 4*v[2]^3 - 2 + 2*v[2]
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
[0.276597509679878506, [0.0364560120817733,0.603788442821000]]


# with approximated gradient estimated "by hand"
objgrad := proc(v, w)
        local eps  := 1e-8:
        w[1] := ( obj(v+~[eps, 0]) - obj(v-~[eps, 0]) )/(2*eps):
        w[2] := ( obj(v+~[0, eps]) - obj(v-~[0, eps]) )/(2*eps):
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
[0.276597509679878562, [[0.0364560121188285,0.603788442801479]]


# with approximated gradient computed with diff
objgrad := proc(v, w)
        w[1] := fdiff(obj, [1], v);
        w[2] := fdiff(obj, [2], v);
end proc:

NLPSolve(2, obj, objectivegradient=objgrad);
Error, (in Optimization:-NLPSolve) invalid input: fdiff expects its 3rd argument, X, to be of type {algebraic, equation, list(algebraic), list(equation), set(equation)}, but received Vector[row](2, {(1) = 1.0, (2) = 1.0}, datatype = float[8])


Thanks in advance

Hi,

I have a function of 3 variables (PiM) which I can use in plot3d given the first argument while the other two arguments are functions of the two variables I use in plot3d.

In the code I attached below, I am plotting 2 planes using plot3d, but I cannot implicitplot where these two planes intersect. COuld you please take a look at my code?

Thanks.

maple_primes_question.mw

 

 

Hi
I have a huge trigonometric expression in Maple with an approximate length of length(.)=397593353.

When I compute this expression in Matlab, I receive another expression with a much smaller length, and the reason is that Matlab is using subexpressions to calculate the main expression. However, I need to do this in Maple.

I have already tried to simplify, but it didn't work.
The maple worksheet & a screenshot of the Matlab subexpression is attached.

See below file for expression in maple (Please run the "Main.mpl" in the attached file.):

Ldiff.zip

And part of the expression in Matlab is shown in the below picture

Where the subexpressions (again in Matlab) are shown below:

Let a,b,c,d and E be constants.

Prove that Laplace{at^-c+bt^-d} = E{as^-c+bs^-d}

if and only if c+d=1 and E= +or-  sqr(pi*csc(c*pi))

Given the property of Gamma:

Gamma(p)Gamma(1-p)=pi/(sin(p*pi)), 0<p<1

This is from an old Schaums outline on Laplace Transforms.

By hand i get  E{as^-d+bs^-c}.

Cant figure out how to get Maple to express this.

Greeting to all of you, I'm having problem in searching for R in this silmutaneious equation. How do I solve this?

 

Please help me to solve the system of nonlinear ordinary differential equations with the help of the Homotopy perturbation method in MAPLE. I have attached a worksheet please check.  Please please help me.

Thank you

HELP.mw

Hi,

Is there a way to change the font type and size when printing a table of data using DocumentTools:-Tabulate? Also can I change the column width?

DocTabFont.mw

I have calculated z=f(x,y) for x from 0 to 5 and y from 0 to 5 by taking step size 0.5  and stored it in a matrix M. Now I am trying to plot the resultant matrix having order 11x11. Where x and y values are ranging from 0 to 5. But If I use this command
matrixplot(M, heights = histogram, colorscheme = ["Blue", "Green", "Yellow", "Red"])
It is taking 0 to 11 on both x and y axis. It must be 0,0.5,0.1,0.15...5.
How to change the values of x and y axis manually?

hi! how can I write it correct?

this is the parametric curve in cartesian coordinates:

spacecurve([2*t^3 - 2*t, 4*t^2, t^3 + t], t = -1 .. 1, color = black, numpoints = 1000, orientation = [90, 90, 90]);

and this should be the same curve but in spherical coordinates:

spacecurve([sqrt(5)*(t^3 + t), arccos(1/sqrt(5)), arccot((t^2 - 1)/(2*t))], t = -1 .. 1, coords = spherical, color = black);

I rewrite that parametrization using formula from this page 

https://en.wikipedia.org/wiki/Spherical_coordinate_system

why doesn't it work?

help on structured type says

| identical(expr) an expression identical to expr

and

The type identical(expr) matches the expression expr identically. If there is more than one expr (i.e. identical(expr1,expr2,...)), then this type matches any one of the exprN identically.
 

Then why does the following produce the same output?

restart;
expr:=x*A[2]+A[1];
select(type,expr,'`*`'({anything, identical(x^2)}));
select(type,expr,'`*`'({anything, identical(x)}))

x*A[2]

x*A[2]


I would have expected only the second select to find x*A[2].

What do I need to only select anything*x^2 without selecting anything*x ?

Actually anything in identical gives same result

select(type,expr,'`*`'({anything, identical(zzzzz)}));

x*A[2]

So I must be misunderstanding something about identical and how it works.  I want to match only anything*x^2 and nothing else. How to do that?

all these things are trivial to do use pattern matching. But in Maple, one is supposed to use structured types.

 

I can't figure this one out.

I need to pick out the subexpression   anything*sin(3*x) from an expression.

it works, when the expression is   anything*sin(3*x)+something else. But when the expression is exactly  anything*sin(3*x) then select returns and not anything*sin(3*x) as I was expecting.

So I must be doing something silly, but do not see it.

restart;
TypeTools:-AddType('type_1', '`*`'({anything,identical(exp(3*x))}));
expr:=25*A[1]*exp(3*x);
type(expr,type_1);

returns true. good. Now I test it on 

select(type,expr+sin(x),type_1) ;

and this returns what is expected. 25*A[1]*exp(3*x) but when I type

select(type,expr,type_1) ;

it return

reading select help page did not help.  Tried flatten, inplace.

I can do this using patmatch

patmatch(expr,a::anything*exp(3*x),'la');la

But why is select not working in the above? What is the correct way to do this so it works for a*expr+anything and also for a*expr only? This is done inside a function and not interactive. So I need it to work for both cases, since the input can be anything, but I only need the term anything*exp(3*x) pulled out.

 

Hi,

As I am continuing to use Maple, I find I use multiple customized worksheets and documents as well as a maple student guide or AEM guide.......How can I save the workspace with these other documents so that I don't have to rebuild them everytime I use that customized Maple system?

Thanks for your help!

Frank

When I work with the fsolve and the number of variables is greater than 9, I have to use the op very carefully, because the order of the variables changes. The same thing happens when working with dsolve(numeric), which is especially inconvenient. For example, the RootFinding [Isolate]  works fine.
I ran into this a very long time ago and I have examples with 15 variables. It is completely unclear why such was done.
How to work with it or how to avoid it?
Example of the same solution using  fsolve and RootFinding [Isolate]

restart:
 CD1 := -.5; CD2 := 2; CD3 := 1.; 
 g1 := 5.; g2 := 3.; g3 := 2.; 
 cg1 := 0.; cg2 := 3.7; cg3 := 1;
 cd1 := 7.5; cd2 := 0; cd3 := 0; 
 L1 := .72; L2 := 8.6; L3 := 5.5; L4 := 1.25; L5 := 3.102; L6 := 5.1; L7 := 7.; 
f1 := (CD1-x4)^2+(CD2-x5)^2+(CD3-x6)^2-L1^2; 
f2 := x1-5; 
f3 := x5-1.45; 
f4 := (g1-x1)^2+(g2-x2)^2+(g3-x3)^2-L3^2; 
f5 := (x7-x1)^2+(x8-x2)^2+(x9-x3)^2-L2^2; 
f6 := (cg1-x7)^2+(cg2-x8)^2-(cg3-x9)^2-L4^2; 
f7 := x7+x8-1.2*cg2; 
f8 := (x4-x7)^2+(x5-x8)^2+(x6-x9)^2-L5^2; 
f9 := (cd1-x10)^2+(cd2-x11)^2+(cd3-x12)^2-L6^2; 
f10 := (x1-x10)^2+(x2-x11)^2+(x3-x12)^2-L7^2;
f11 := x11-.1*x12; 
f12 := x1-x2-x3-x4+x5+x6+x7+x8+x9+x10+x11-x12; 
fsolve({f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12}); 
RootFinding[Isolate]([f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12], [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12])[4];
  {x1 = 5.000000000, x10 = 6.265979021, x11 = 0.4923895285, 
  x12 = 4.923895285, x2 = 7.363909611, x3 = 5.347580157, 
    x4 = -0.4802494112, x5 = 1.450000000, x6 = 0.5357695462,
    x7 = 2.014012007, x8 = 2.425987993, x9 = -1.029002454}
[x1 = 5., x2 = 7.363909611, x3 = 5.347580157, x4 = -0.4802494112, 
  x5 = 1.450000000, x6 = 0.5357695462, x7 = 2.014012007,
  x8 = 2.425987993, x9 = -1.029002454, x10 = 6.265979021,
  x11 = 0.4923895285, x12 = 4.923895285]


 

My first day attempting Maple so probably something simple about environment variables.

I'm trying to use Digits in an expression to set and use the preceision. It seems to set the value if used in a procedure but seems to update the variable after the execution of multiple commands executed together - also setting a variable from Digits, updating it, then using that in evalf doesn't help.

Digits := 1

Digits := Digits + 1; Digets; 1.0/3;

Gives 1 digit, Setting of Digits takes affect after the evaluation.

f := proc() Digits + 1; 1.0/3; end proc

f();

2 digits - so the setting of Digits takes effect before the evaluation. Looks like the procedure is executed as separate commands.

So repeated executes of 

f(); Digits++;

Will increment the precision as will

f := proc() Digits++; print(evalf[Digits](1.0/3)); return Digits; end proc; Digits := f();

Also

a := 1; a := a + 1; evalf[a](1.0/3);

Gives 2 digits

a := Digits + 1; evalf[a](1.0/3);

Gives 1 digit.

a := eval(Digits + 1); evalf[a](1.0/3);

Gives 1 digit.

A := [1, -2, 3]:u := `<,>`(0, -2, 2):v := `<,>`(5, 8, -3):
PL := proc (A, u, v) local d, Det, AP, t, U, V;
AP := `<,>`(x-A[1], y-A[2], z-A[3]);
Matrix(`<|>`(`<,>`(AP), `<,>`(u), `<,>`(v)));
Det := LinearAlgebra:-Determinant(%); d := igcd(coeff(Det, x), coeff(Det, y), coeff(Det, z), tcoeff(Det));
print(`Une équation cartésienne du plan est :`);
t := Det/d; print([t = 0]);
print('Une*représentation*paramétrique*du*plan*est; -1');
U := convert(u, list); V := convert(v, list);
[x = lambda*U[1]+mu*V[1]+A[1], y = lambda*U[2]+mu*V[2]+A[2], z = lambda*U[3]+mu*V[3]+A[3]] end proc;
PL(A, u, v);

plan3p := proc (A::list, B::list, C::list)
local d, M, N, P, Mat, Det, t, U, V;
M := `<,>`(x-A[1], B[1]-C[1], C[1]-A[1]); N := `<,>`(y-A[2], B[2]-C[2], C[2]-A[2]); P := `<,>`(z-A[3], B[3]-C[3], C[3]-A[3]);
Mat := Matrix([M, N, P]);
Det := LinearAlgebra:-Determinant(%);
d := igcd(coeff(Det, x), coeff(Det, y), coeff(Det, z), tcoeff(Det));
print(`Une équation cartésienne du plan est :`);
t := Det/d; print([t = 0]); print('Une*représentation*paramétrique*du*plan*est; -1');
U := A-B; V := B-C;
[x = lambda*U[1]+mu*V[1]+A[1], y = lambda*U[2]+mu*V[2]+A[2], z = lambda*U[3]+mu*V[3]+A[3]] end proc;
A := [-6, 3, -2]; B := [5, 2, 1]; C := [2, 5, 2];plan3p(A, B, C);
How to know if these procedures are correct or not. Thank you.

First 78 79 80 81 82 83 84 Last Page 80 of 2120