## 85 Reputation

6 years, 336 days

## Minus sign...

@Carl Love
Great! Thanks a lot. Anyway I found that un minus sign remains in some cases. It does not operate with the simple set S:={X,-X}...

Not easy!

Hello,

Thank you for your response. I will take your remarks into account in the future.

I will therefore answer your questions. In fact, I have polynomials with two categories of variables:

Category 1: the variables X1, X2,..., XN,

and a second category: the variables U1, U2,..., UK.

These polynomials are on the field of reals.

I then consider the polynomials of the variables of category 1 having polynomial coefficients with the variables of the second category.

At the end of my calculations, I obtain sets or lists of such polynomials, and in these sets or lists there are redundancies from the point of view of the polynomials in the variables of category 1. More precisely, I obtain polynomials that differ only by one factor belonging to the polynomials in the variables of category 2. I would like to keep only the common polynomial part in the variables of category 1.

For example:

(3*U2-U4^4)*(X1+ U1^2*X2-(3*U2-1)*X3^2)

and

(4*U1-5*U2^2+U4)*(X1+ U1^2*X2-(3*U2-1)*X3^2)

I would then like to keep in my list or set only the polynomial:

(X1+ U1^2*X2-(3*U2-1)*X3^2).

Is my precision appropriate?

## @Mac Dude  Hello! Thank you for y...

Hello!

I'm on Mac and using the "Preview" software allows conversion of png files to eps format via the file printing service.

It is a somewhat wobbly solution to say the least.

I'll do like you: do the figures with Mathematica, exponentially slower than Maple unfortunately. My image files take 10 times longer to be generated with Mathematica than with Maple.....: 3 minutes with Maple, half an hour with Mathematica...

Mathematica's "broom car" Maple problems...!

I can't believe Maple isn't solving this problem.

Thank you again.

Jaqr

## Unfortunately......

Hello

Thank you very much, unfortunately I forgot to say I'm on Mac. Nevertheless, I tried your procedure with a path in my user folder. It does not work. No files are registered.

Thank you again.

Jaqr

## Finally resolved...

I found the solution....

This is not due to MAPLE but the way pathnames must be typed in a shell with mac osx.

In such situation, the pathnames with blank spaces must be indicated between quotation marks.

Hence, we have the three poccibilities for instance:

First case:

####################

####################

Second case:

####################

####################

Third case:

####################

with(StringTools):
Path:=cat(currentdir(),"/a.dat");

UnixCommand:=cat("curl -m 2 -o """,Path,""" --insecure https://www.google.com/?gws_rd=ssl");
system(UnixCommand);

####################

Ouch!

But, problems if the pathname contains an underscore.....

## OK, but.......

Hello, it does not work unfortunately.

I wrote the following code:

####################

with(StringTools):
Path:=cat(currentdir(),"/a.dat");

CorrectedPath:=Substitute(Path," ","\\ ");
UnixCommand:=cat("curl -m 2 -o ",CorrectedPath," --insecure https://www.google.com/?gws_rd=ssl");
system(UnixCommand);

####################

But, again it does not work.

???

So....

## OK...

Thank you very much Rouben. It works!

## NumericEventHandler environment...

@acer

Hello,

I have no particular example.

I just try to correctly define the procedure to obtain the value 2 whenever x equals either +/-infinity or if there is a division by zero as input.

Now, I corrected the code as follows:

```> NumericEventHandler(division_by_zero=proc() infinity ; end proc):
> f:=proc(x)
local u;
Digits:=20;
if x>10^10 and (x<>+infinity or x<>-infinity)
then u:=1/x; evalf[27](2/Pi*arccos((u*u-1)/(1+u*u)))
elif x<>+infinity or x<>-infinity
then 2.
else
evalf[27](2/Pi*arccos((1-x*x)/(1+x*x)))
end if
end proc:```

And, I obtain:

```> f(1);f(10000000000000);f(-infinity);f(+infinity);f(0/0);f(1/0);
2.
1.99999999999987267604552648
2.
2.
2.
2.```

But, the portion of code:

`> NumericEventHandler(division_by_zero=proc() infinity ; end proc):`

is ineffective if put inside the procedure code.

Anyway, what do you mean 'acer' by "local context analogous to environment variables"?

Best regards

Jaqr

## A so little epsilon...

Hi!

Your solution is theright one. Epsilon must be modified. It is the critical value in the NonLinearFit process.

Moerover, epsilon can take a relatively high value because just a fit is done. So taken an epsilon value such that 1.0e-14 is ridiculous or fitting. Taking higher values for epsilon (e.g., 1.0e-4) with digits=15 for instance, allow a very good fit in a few seconds for the little computer I have got!!

So, your solution is the best one.

Thank you very much again.

## Learn to read... and so on...!...

Ok, I ought to learn to read..!

A last question, sometimes, with other data and a far more complex expression in definition of the Dens function, I obtained complex values as results from the NonLinearFit procedure.

I put Re(...) commands at different places to solve the problem. But, I did not clearly identified the problem; due to roudoff errors certainly but how efficiently solve that issue ? In the Dens function or in the first argument of NonLiinearFit ?
Or, increasing the number of digits would be another solution, but with longer times for computations unfortunately.

I tried a lot of solutions but it is not clear.

Best regards

Jacqr

Thank you a lot. It works very well now.

I tried to modify the procedure defining the Dens function as you indicated. But, instead of using the code: 'procname'(args) , I used NULL or the numeric value 0. And of course, it didn't work satisfactorily as you can easily imagine.

Also, in the help page for NonLinearFit, the string u must be between brackets like that: [u] . Why don’t you use this syntax ?

Sincerely yours,

And thank you again.

Jacqr

## A more complete code with data...

Hello,

Here below is a more complete code with the data.

Also, remember I use MAPLE 14.

Sincerely yours

Jacqr

#####################################################

restart:with(plots):with(Statistics):with(ArrayTools):
#
Dens := proc(v)
local theta, r;
evalf[8](
Int(Int(
4*r/(1-0.84*cos(theta)^2)^(1/2)*exp(-r*(6.25-5.245*cos(theta)^2)^(1/2))
, theta = 0.0.. 2*Pi)
, r = 0. .. v)
) assuming v>=0
end proc;
proc(v)  ...  end;
a:=1.4:b:=.13:
#
depth:=[.033, .099, 0.198, 0.264, 0.363, 0.759, 1.25, 1.748, 2.246, 2.744, 3.232, 3.73]:
veloc:=[0.180, 0.25, 0.296, 0.324, 0.516, 0.606, 0.757, 0.760, 0.784, 0.804, 0.794, 0.790]:
veloc_errors:=[0.20, 0.15, 0.15, 0.170, 0.150, 0.10, 0.05, 0.05, 0.02,0.02, 0.02, 0.03]:
#
plot_veloc_sim:=plot( b*(1+a*u)/u*Dens( u/(1+a*u) )  , u = 0.0..4.0,color=["Blue"]):
plot_veloc := ErrorPlot(veloc, xcoords = depth, yerrors = veloc_errors):
display({plot_veloc_sim,plot_veloc});

#

FitFinalDens := NonlinearFit(
b*(1+a*u)/u*Dens(u/(1+a*u))
, depth
, veloc
, [u]
, initialvalues = [a = 1.4, b = 0.13]
, parameternames = [a, b]
, output = [leastsquaresfunction, residuals, parametervector]
, parameterranges=[a=1.1..3.0,b=0.02..0.8]
);
#
a= FitFinalDens[3][1];
b= FitFinalDens[3][2];
#
Error, (in Statistics:-NonlinearFit) invalid input: no implementation of NonlinearFit matches the arguments in call, 'NonlinearFit(.13*(1+1.4*u)*(Int(Int(4.*r*exp(-1.*r*(6.25-5.245*cos(theta)^2)^(1/2))/(1.-.84*cos(theta)^2)^(1/2), theta = 0. .. 6.2831854), r = 0. .. u/(1.+1.4*u)))/u, op(w), [u], initialvalues = [1.4 = 1.4, .13 = .13], parameternames = [1.4, .13], output = [leastsquaresfunction, residuals, parametervector], parameterranges = [1.4 = 1.1 .. 3.0, .13 = 0.2e-1 .. .8])'

1.4 = FitFinalDens[3][1]
0.13 = FitFinalDens[3][2]

#####################################################

Also, I tried to run the file dataFit.mw, and I obtained:

#####################################################

restart;
with(Statistics):
#
# Define a "useful" procedure
#
Dens := proc(v)
local theta, r;
evalf[8]
( Int
( Int
( 4*r/(1-0.84*cos(theta)^2)^(1/2)*exp(-r*(6.25-5.245*cos(theta)^2)^(1/2)),
theta = 0. .. 2*Pi
),
r = 0. .. v
)
)  assuming v>=0
end proc:

#
# OP too inefficient to provide data for fit, so generate
# data using the model function, adding a random value to
# the dependent values. Use parameter values aPar=2.5, and
# bPar=0.75, just because I have to use something, and these
# are in the within the ranges specified by the OP.
#
# The fit process therefore *ought* to return something
# *close* to these values
#
aPar:= 2.5:
bPar:= 0.75:
r:= rand(-0.1..0.1);
depth:= [i \$ i=1..10]:
veloc:= [ seq
( bPar*(1+aPar*k)/k*Dens(k/(1+aPar*k))+r(k),
k in depth
)
]:
Error, invalid input: rand expects its 1st argument, r, to be of type {posint, integer .. integer}, but received -.1 .. .1

#
# Set up and perform the fit
#
f:= (z, aVal, bVal)-> bVal*(1+aVal*z)/z*Dens(z/(1+aVal*z)):
FitFinalDens := NonlinearFit
( f(u,a,b),
depth,
veloc,
u,
initialvalues = [a = 1.4, b = 0.13],
parameternames = [a, b],
output = [residuals, parametervector],
parameterranges=[a=1.1..3.0, b=0.02..0.8]
);
Error, (in Statistics:-NonlinearFit) invalid input: no implementation of NonlinearFit matches the arguments in call, 'NonlinearFit(b*(1+a*u)*(Int(Int(4.*r*exp(-1.*r*(6.25-5.245*cos(theta)^2)^(1/2))/(1.-.84*cos(theta)^2)^(1/2), theta = 0. .. 6.2831854), r = 0. .. u/(1.+a*u)))/u, w[() .. (), 1 .. -2], w[() .. (), -1], (b*(1+a*u)*(Int(Int(4.*r*exp(-1.*r*(6.25-5.245*cos(theta)^2)^(1/2))/(1.-.84*cos(theta)^2)^(1/2), theta = 0. .. 6.2831854), r = 0. .. u/(1.+a*u)))/u, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2.979399150+r(), 3.310608375+r(), 3.436306050+r(), 3.502378069+r(), 3.543099368+r(), 3.570706800+r(), 3.590655155+r(), 3.605742591+r(), 3.617552791+...
#
# Plot the data used and the fit achieved
#
dataPoints:= plots:-pointplot( depth,
veloc,
symbol=solidcircle,
symbolsize=20
):
fitCurve:= plot( z-> f( z,
FitFinalDens[2][1],
FitFinalDens[2][2]
),
1..10
):
plots:-display( [ dataPoints,
fitCurve
]
);
Error, (in plots:-pointplot) points cannot be converted to floating-point values
Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct
Error, (in plots:-display) expecting plot structures but received: [dataPoints]

#####################################################

 1 2 Page 2 of 2
﻿