Preben Alsholm

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@leafgreen This is just a comment. Try the following:
 

restart; 
u:=-(x[1]-x[2])/((x[1]-x[2])^2+(y[1]-y[2])^2)-(x[1]-x[3])/((x[1]-x[3])^2+(y[1]-y[3])^2);
F:=unapply(u,x[1], y[1], x[2], y[2], x[3], y[3]);
f:=(x,y)->-(x[1]-x[2])/((x[1]-x[2])^2+(y[1]-y[2])^2)-(x[1]-x[3])/((x[1]-x[3])^2+(y[1]-y[3])^2);

You will see that unapply uses other symbols in defining the function. But you get the function you want.
In the second example (f) the function f is a function of x and y (typically vectors). This syntax is used e.g. by dsolve/numeric behind the scene, but can also be used directly by the user.

You should upload the worksheet int the MaplePrimes editor. Use the fat, green arrow to do that.

@ernilesh80 You have equality signs ( = ) instead of assignments (:= ) in the line that should assign to best_value.

Incidentally, you have defined best_value as a list, not as an array. You are allowed to assign to small lists (length less than 101), but it is a bad idea since an entirely new list is created every time. Lists are not mutable as opposed to arrays, matrices, vectors, and tables.
So use an array instead (here basically for matters of principle).
best_value:=Array([0,0,0,0,0]);
### Try this:
 

restart;
L:=[0,0,0,0,0];
L[1]:=1;
L;
L:=[0$101];
L[1]:=1;

 

@ernilesh80 You forgot to do
with(LinearAlgebra);
before the loop, e.g. at the very top.
On the other hand I would use the long form for the Hessian VectorCalculus:-Hessian instead of using with(VectorCalculus). That package redefines all kinds of normal things, which I find disturbing.

@Harry Garst This clearly is a bug in minimize.
I believe that it can be traced from minimize to
`minimize/cell/check`, from there to
`minimize/cell/internal`, then to
`minimize/cell/decouple` then to
`minimize/cell/sum` then to
`minimize/cell/variate` then to
`minimize/cell/univariate`
after which I gave up.
###################################################
A few observations:
1. If you copy the final temp2 and paste it in a fresh worksheet then there is no problem:
 

temp2:=(-3.79741609404203+1.21140500697585*sqrt(v^2))^2+(-1.33163418865668+1.21140500697585*sqrt((1-v)^2))^2+(-.865852283271325+1.21140500697585*sqrt((2-v)^2))^2+(-1.40007037788597+1.21140500697585*sqrt((3-v)^2))^2+(-.934288472500622+1.21140500697585*sqrt((4-v)^2))^2+(-2.46850656711527+1.21140500697585*sqrt((5-v)^2))^2+(-4.00272466172992+1.21140500697585*sqrt((6-v)^2))^2+(-4.53694275634457+1.21140500697585*sqrt((7-v)^2))^2+(-7.07116085095921+1.21140500697585*sqrt((8-v)^2))^2+(-7.60537894557386+1.21140500697585*sqrt((9-v)^2))^2;
minimize(temp2,v=1..8,location);

2. If you use abs(xxx) instead of sqrt(xxx^2) in the model as well as in temp2 then there is no problem.
3. During my wild goose chase through subprocedures of minimize I saw the name forget_Proc come up. This made me try this:
 

restart;
X := Vector([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]):
d := 2.730469991:
Y:=Vector( [5, 9, 11, 12, 14, 14, 14, 15, 14, 15]):
m := Statistics:-LinearFit(a+b*t+c*sqrt((t-d)^2), X, Y, t);
#m2 := Statistics:-LinearFit(a+b*t+c*abs(t-d), X, Y, t);
forget(minimize);

The response from forget minimize was the error message:

Error, (in forget) lexically scoped parameter out of context
If you uncomment the m2 line, comment the m line, and start over, then there is no error from forget.

I shall submit an SCR.

 

Could you provide us with all the code in the form of text or an uploaded worksheet?
Images don't help much.
Nobody is going to type the stuff and they won't even know how temp2 was defined or what happened before.

@ernilesh80 Since you don't know how large the two arrays have to be you can just define them as arrays:
pd_arr:=Array();
id_arr:=Array();
###
Then in the assignments to pd_arr and id_arr in the loops you must use parentheses instead of square brackets as in
pd_arr(pd, 1) := op_value[1]; pd_arr(pd, 2) := op_value[2]; pd_arr(pd, 3) := op_value[3]; pd_arr(pd, 4) := op_value[4];
Do similarly for id_arr.
The loops take a while since
nops~([T_arr,E_arr,W_arr,p_arr]);
`*`(op(%)); 
returns 7436529.
I stopped the computation after a while and inspected both arrays by just doing:
pd_array;  # at that time a 1..8667x1..4 array
id_array ;  # at that time a 1..46980x1..4 array, i.e. larger than the 1..10000x1..4 you used.
## Incidentally, it may not be more efficient to do this, but it is shorter:
pd_arr(pd, 1..4) := Array(op_value);
and similarly for id_arr.

@memdream You should be aware that (-1)^(1/4) in Maple is the principal root:
evalc( (-1)^(1/4) );
                                 (1/2)*sqrt(2)+(1/2*I)*sqrt(2)

@Rouben Rostamian  Yes, when I paste the 2D input on a 1D input line I get
exp(4.605170186*`9`)
The factor `9` is understood by Maple as a name, not as the integer 9.

Since nobody is going to type your expression from the image you should upload a worksheet using the fat green arrow in the MaplePrimes editor.

Why not give us the specific function? (As text or an uploaded worksheet!)

@Rouben Rostamian  Yes, you are right. That is why the -1 is repeated, since res still has the value from i = -1.

@tomleslie gamma is Euler's constant, thus gamma is approximately 0.5772156649.

If x and y are not assigned values of any kind (using the assignment operator :=  as in x:=23 ) then the result of the statement
x+y;
is just that x+y. What else would you expect?
If you do
x:=a;
y:=78;
then
x+y;
evaluates to a+78 assuming that the variable a is unassigned.

For us to understand what you actually did you should upload a worksheet using the fat green arrow in the MaplePrimes editor.

@MrMarc To confirm that you need unevaluation quotes, try this:

rand()$10;
## and then
'rand()'$10;
## Take a look at the results from your Maple 2017.

The sequence operator `$` evaluates its arguments fully as the first thing (the normal behavior in Maple).
Thus rand() is evaluated once in the first case above and the result is a sequence of 10 identical numbers.
In the second case full evaluation also takes place, but full evaluation of an expression with unevaluation quotes just means removal of the quotes, thus when `$`gets to do its actual work it sees rand() and not a number as in the first case.

If you use seq instead you won't have this 'problem'. seq has special evaluation rules (as do e.g. add and mul).
With or without unevaluation quotes this works as intended:

seq(rand(),i=1..10);

First 63 64 65 66 67 68 69 Last Page 65 of 231