henrylyl

20 Reputation

2 Badges

8 years, 296 days

MaplePrimes Activity


These are replies submitted by henrylyl

@Carl Love 

I initiated both G and pG with Array(1..3),  so If I define G[1],G[2],G[3] explicitly like I did then I have an Array?  but if I define pG=[ A, B, C] then I have a list? even though pG was defined as Array(1..3) at the beginning? 

 

By the way, I found that definning an expression as a element of an Array is tricky because if I have say

expr1:=Array(1..2, x^2, x);

eq2:= y^2 + z^2 = p^2;

expr2:= solve(subs(y=expr1[1],eq2), p)

then there is error

but if you define expr1:=[x^2,x] then everything works fine...

 

@Carl Love 

 

thanks carl.  I find that  display(Array([display(plot1, plot2),display(plot3, plot4)])) is better for me.  because I do not know what does ^% mean...

 

by the way,  <XXX,  yyy, zzz> is a short cut to create column vector, what is the short cut to create row vector?

 

Thanks

@Carl Love 

 

Thank you Carl! I have another question, when I use the "useunits"  plot option, it does not automatically convert unit display on the plot.  It seems it is only a "display".  For example, if my function has out put value of

100N at 50MPa with useunits=[Unit(MPa),Unit(N)]

when I change to useunits=[Unit(MPa, Unit(kilopond)],  the numeric value does not change. is there away the plot can automatically convert unit without me using the convert cmd?

 

Thanks

Hi,

I have tried the download link in the question after updating it.  It is working for me.  If anyone see the 404 screen again, please let me know and I can upload it again.  Thank you for your help.

 

 

@henrylyl 

 

the link in the original post is updated now..it should be working

 

 

@Carl Love

I found a way do my problem.  thanks

 

Thanks Acer,

I used maple 18 to create the worksheet.  There maybe some changes in explore in v18 because the error was about mathing the input of explore parameters .  I hope maple player 18 will come soon. 

Additional question,

If I have restart in the code of button component (or any component), it does not affect the global environment in the worksheet

Is there a way I can do it?  I need it because I want to allow user the option to clear all memory in the math engine as they interact with my worksheet, but that would mean I have to run the startup code automatically again if the user click this clear button.

Thanks

Henry

 

I took advice from this post and did the following

restart;

X := Vector([253, 253, 527, 802], datatype = float[8]);

Y := Vector([214, 212, 410, 618], datatype = float[8]);

SLRrepeatedsample:=proc(A,B,N,CI)
uses ArrayTools, Statistics, RandomTools;
local x, y, n, ymu, ySE, yvar, x2,b,bCI;
global X1,Y1;
X1:=A;Y1:=B;
n := Size(X1, 1);
b := LinearFit([1, t], X1, Y1, t,output = parametervalues);
ySE := LinearFit([1, t], X1, Y1, t,output = residualstandarddeviation);
x2 := X1^~2;
for i from 1 by 1 to N do
   x:=Generate(float(range = min(X1)..max(X1)));
   ymu := b[1]+~b[2]*x;
   ySE := (1+1/n+sqrt(((x-Mean(X1))^2)/(add(x2[j], j = 1..n)-n*(Mean(X1))^2)));
   yvar := RandomVariable(Normal(ymu, ySE));
   y := Sample(yvar, 1)[1];
   X1(n+1) := x;
   x2:= X1^~2;
   Y1(n+1) := y;
   b := LinearFit([1, t], X1, Y1, t,output = parametervalues);
   ySE:= LinearFit([1, t], X1, Y1, t, output = residualstandarddeviation);
   n := Size(X1, 1);
od;
bCI := LinearFit([1, t], X1, Y1, t, confidencelevel = CI,output = confidenceintervals);
return b, bCI,ySE,n;
end proc:

 

Why this procedure update my original X and Y vector?

I already define a separate global parameter X1 and Y1 to avoid it and I did not update X and Y in the procedure.  I tried using other name such as XX and YY but the same thing happen.  

 

 

Thanks to everyone in this post.  Now the procedure is running like I want it to.  Love this community with such a quick response.  I think you  response faster than maple customer service.

 

 

@Carl Love 

Thanks Carl, I have corrected LinearFit.  Because I want to use contatenate to append x to X for each for loop iteration, I set x to be vector even though it is only 1 value (as case for ymu).  Thanks for pointing out the error in ySE! that is a great help.  now I am closer to completing this procedure but I think I have more errors than I initially thought.  Thank you for answering this post!

I am still struggling where the remain mistakes are

Here is the corrected code with the new error message..

restart; with(ArrayTools); with(Statistics); with(RandomTools); X := Vector([1, 2, 3, 4, 5, 6], datatype = float);
Y := Vector([2, 3, 4, 3.5, 5.8, 7], datatype = float);

SLRrepeatedsample:=proc(X,Y,N,CI)
local x, y, n, ymu, ySE, yvar, x2,b,bCI;
n := Size(X, 1);
b := LinearFit([1, t], X, Y, t, confidencelevel = CI,output = parametervalues);
ySE := LinearFit([1, t], X, Y, t, confidencelevel = CI,output = residualstandarddeviation);
x2 := X^~2;
for i from 1 by 1 to N do
x:=Vector([Generate(float(range = min(X)..max(X)))],datatype=float);
ymu := (b[1]+~b[2]*x);
ySE := (1+1/n+sqrt(((x[1]-Mean(X))^2)/(add(seq(x2[k], k = 1..n)[j],j=1..n)-n*(Mean(X))^2)));
yvar := RandomVariable(Normal(ymu[1], ySE));
y := Vector([Sample(yvar, 1)], datatype = float);
X := Concatenate(1, X, x);
x2:= X^~2;
Y := Concatenate(1, Y, y);
b := LinearFit([1, t], X, Y, t, confidencelevel = CI,output = parametervalues);
ySE:= LinearFit([1, t], X, Y, t, confidencelevel = CI,output = residualstandarddeviation);
n := Size(X, 1);
od;
bCI := LinearFit([1, t], X, Y, t, confidencelevel = CI,output = confidenceintervals);
return b, bCI;
end proc:

SLRrepeatedsample(X, Y, 2, .95);

Error, (in SLRrepeatedsample) invalid left hand side in assignment

 

 

SLRrepeatedsample_pr.mw

restart; with(ArrayTools); with(Statistics); with(RandomTools); X := Vector([1, 2, 3, 4, 5, 6], datatype = float);

Y := Vector([2, 3, 4, 3.5, 5.8, 7], datatype = float);

SLRrepeatedsample:=proc(X,Y,N,CI)
local x, y, n, ymu, ySE, yvar, x2,b,bCI;
n := Size(X, 1);
b := Linearfit([1, t], X, Y, t, confidencelevel = CI,output = parametervalues);
ySE := Linearfit([1, t], X, Y, t, confidencelevel = CI,output = residualstandarddeviation);
x2 := X^~2;
for i from 1 by 1 to N do
x:=Vector([Generate(float(range = min(X)..max(X)))],datatype=float);
ymu := (b[1]+~b[2]*x);
ySE := (1+1/n+sqrt(((x-Mean(X))^2)/(add(seq(x2[k], k = 1..n)[j],j=1..n)-n*(Mean(X))^2)));
yvar := RandomVariable(Normal(ymu, ySE));
y := Vector([Sample(y__var, 1)], datatype = float);
X := Concatenate(1, X, x);
x2:= X^~2;
Y := Concatenate(1, Y, y);
b := Linearfit([1, t], X, Y, t, confidencelevel = CI,output = parametervalues);
ySE:= Linearfit([1, t], X, Y, t, confidencelevel = CI,output = residualstandarddeviation);
n := Size(X, 1)
od;
bCI := Linearfit([1, t], X, Y, t, confidencelevel = CI,output = confidenceintervals);
return b, bCI
end proc:

Warning, `i` is implicitly declared local to procedure `SLRrepeatedsample`

SLRrepeatedsample(X, Y, 1, .95);
Error, (in rtable/Sum) invalid arguments

@Preben Alsholm

Thanks Preben.  I took your advice and used Code Edit region.  Now I have another error..Can you or anyone reading this show me how to use DEBUG to find where I made mistake? 

Error, (in rtable/Sum) invalid arguments.  I think it is one of the function I use was called incorrectly...but which one?

 

SLRrepeatedsample_pr.mw

Page 1 of 1