Preben Alsholm

MaplePrimes Activity


These are replies submitted by Preben Alsholm

Notice that each time you call foo a new local is created:
 

foo:=proc(n)
   local x;
   x^n;
end proc;
x1:=foo(1);
x2:=foo(1);
x1-x2;

x1-x2 prints as x-x and doesn't simplify to zero.
If you look at their addresses you will see that they are different:
addressof(x1);
addressof(x2);

@nm Clearly the problem on the interval -1..1 can be transformed to a problem on 0..2, which I shall do below.
I agree with Rouben that your argument in the pdf file fails when you assert that B must be taking to be zero since otherwise you have two unknowns A and B. But clearly you have infinitely many, since A (and B) must depend on lambda.
From your two equations (3) and (4) together as a linear system in the unknowns A and B follows (if you want a nontrivial solution) that the determinant is zero. The determinant is 2*sin(sqrt(lambda))*cos(sqrt(lambda)), which is sin(2*sqrt(lambda)).
Thus 2*sqrt(lambda) = n*Pi, where n is a positive integer. We still must use one of the two equations (3) or (4).
If you continue along this line you will end up with sine contributions as well as cosine contributions (in general).
## I give the code for the solution using transformation from -1..1 to 0..2.
 

restart;
## First we just document that solving on 0..L is done painlessly:
pde:=diff(u(x,t),t)=diff(u(x,t),x,x);
ibcs:=u(0,t)=0,u(L,t)=0,u(x,0)=f(x);
pdsolve({pde,ibcs}) assuming L>0;
## Now the present problem
icbs2:=u(-1,t)=0,u(1,t)=0,u(x,0)=f(x);
##Changing from -1..1 to 0..2:
sys:=PDEtools:-dchange({u(x,t)=v(xi,t),x=xi-1,f(x)=g(xi)},{pde,icbs2},[v,g,xi]);
res:=pdsolve(sys); # Done as in the beginning.
## Now back to the original variables:
evalindets(res,Integral,s->IntegrationTools:-Change(s,xi=y+1));
res:=u(x,t)=rhs(eval(%,{xi=x+1,g=(xi->f(xi-1))}));
N:=op(indets(res,suffixed(_Z,integer)));
## First taking the contribution from even N:
subs(N=2*m,rhs(res)); 
res1:=subsop(2=(m=1..infinity),%);
evalindets(res1,specfunc(sin),expand);
res1:=simplify(%) assuming m::posint; # redefining res1
## Now taking the contribution from odd N:
subs(N=2*m-1,rhs(res)); 
res2:=subsop(2=(m=1..infinity),%);
evalindets(res2,specfunc(sin),expand,2*m-1);
res2:=simplify(%) assuming m::posint; # redefining res2
## The final solution:
sol:=u(x,t)=res1+res2;
## Examples
eval(sol,f=(x->1-x^2)); #An even function
value(%);
eval(sol,f=(x->(1-x^2)*x)); #An odd function
value(%);
eval(sol,f=(x->(1-x^2)*(x+1))); #The sum of the two: neither even nor odd
value(%);

 

@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.

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