acer

32385 Reputation

29 Badges

19 years, 336 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Is this the kind of thing you are trying to accomplish?

Note that (the way the conditional if..then inside your procedure lambda22sol is set up), if you call procedure lambda22sol a second time without unassigning __old_a then it will return NULL. I suspect that is why you got that error message, because you were calling it twice and so the middle column of matrix1 from the call lambda22sol(0.9) was NULL.

restart;

data:=ExcelTools:-Import(cat(kernelopts(homedir),"/mapleprimes/","data.xlsx")):

with(LinearAlgebra):
lambdaX:=Column(data,1):
PK1X:=Column(data,2):


tensF:=Matrix([[lambda11,0,0],[0,lambda22,0],[0,0,lambda22]]):
tensFbar:=Matrix([[(lambda11/lambda22)^(2/3),0,0],[0,1/sqrt((lambda11/lambda22)^(2/3)),0],[0,0,1/sqrt((lambda11/lambda22)^(2/3))]]):
tensBbar:=Multiply(tensFbar,Transpose(tensFbar)):

kappa:=100:
tensPK:=Multiply(Transpose(MatrixInverse(tensF)),(2/Determinant(tensF))*a*(tensBbar-(1/3)*Trace(tensBbar)*Matrix(3,shape=identity))+kappa*(Determinant(tensF)-1)*Matrix(3,shape=identity)):
PK1:=tensPK[1,1]:
eq:=0=tensPK[2,2]:

lambda22sol:=proc(aValue)
   global __old_a;
   local res, i, eq1, sol1, lambda22Est;
   if not [aValue]::list(numeric) then
      return 'procname'(args);
   end if;
   lambda22Est:=Vector(1..RowDimension(lambdaX)):
   eq1:=Array(1..RowDimension(lambdaX)):
   if __old_a<>aValue then
      __old_a:= aValue;
     for i from 1 to RowDimension(lambdaX) do
             eq1[i]:=eval(eq,[a=aValue,lambda11=lambdaX[i]]):
                sol1:=[fsolve(eq1[i], lambda22)];
                lambda22Est[i]:=sol1[1]:
        end do:
        res:=lambda22Est;
   end if;
end proc:

__old_a:='__old_a':
LL:=lambda22sol(0.9):
matrix1:=<lambdaX|LL|PK1X>:

DS1:=CodeTools:-Usage(
        DirectSearch:-DataFit(abs(PK1),matrix1,[lambda11,lambda22]));
res2:=eval(PK1,DS1[2]):

memory used=9.71MiB, alloc change=0 bytes, cpu time=118.00ms, real time=118.00ms, gc time=0ns

[HFloat(2.866379619163419), [a = HFloat(-0.4500000222184452)], 28]

plots:-display(
  plot3d(eval(PK1,DS1[2]),lambda11=min(lambdaX)..max(lambdaX),
                            lambda22=0.5..1.5,
         style=surface, transparency=0.5),
  plots:-pointplot3d(matrix1,color=red,thickness=3),
  view=min(PK1X)..max(PK1X)
);

 

Download lambda22sol.mw

restart;

H:=Int(simplify(1/(x-1)+sum((k+1)*x^k,k=0..2018)/sum(x^k,k=0..2019)),x);

Int(2020*x^2019/(x^2020-1), x)

eval(value(IntegrationTools:-Change(H,s=x^2020,s)),s=x^2020);

ln(x^2020-1)

Download int_ex.mw

 

In a sense, that could be broken down into steps:  int_ex2.mw
There I replaced the numbers 2018 and 2019 by symbolic names, temporarily, to prevent awkward expansion. The following also works directly:

simplify(int(1/(x-1)+sum((k+1)*x^k,k=0..N)
                     /sum(x^k,k=0..N+1),x));

               ln(x^(N+2)-1)

There is a form, on the Software Change Request page (linked from the Mapleprimes top "More" tab).

(Rewritten question is now asked here.)

The axis mode is part of the generated plot structure (set altogether as the value property of the embedded component), and not a property of the embedded component.

You can add axis[2]=[mode=log] to the dataplot command.

restart;

DetAnalysisNx2:=[seq(0..2,0.1)]:

DetAnalysisDeterm2:=map(x->exp(x^2),DetAnalysisNx2):

DocumentTools:-SetProperty("DeterminantenRaumPlot1",
                           value,
                           dataplot(DetAnalysisNx2, DetAnalysisDeterm2));

DocumentTools:-SetProperty("DeterminantenRaumPlot1",
                           value,
                           dataplot(DetAnalysisNx2,DetAnalysisDeterm2,
                                    axis[2]=[mode=log]));


Download log_mode.mw

restart;

expression1 := -cos(theta)/2 + sin(theta)*sqrt(3)/2;

-(1/2)*cos(theta)+(1/2)*sin(theta)*3^(1/2)

expression3 := convert(expression1, phaseamp, theta);

-cos(theta+(1/3)*Pi)

simplify(expression1 - expression3);

0

 

Download trig_phaseamp.mw

Yes, it can be done using plottools:-transform as follows,

f,g := 1,min(3,1/x):
P:=plot(f-g,x=0..maximize(1/y,y=1..3),filled):
plottools:-transform(unapply([x,y+g],[x,y]))(P);

Of course, you might be able to see that the upper end-point of the x-range is just 1, without having to compute that from maximize(1/y,y=1..3).

And so you might also write down either of these, directly. They each produce a plot with the region shaded.

plottools:-transform((x,y)->[x,y+min(3,1/x)])(plot(1-min(3,1/x),x=0..1,filled));

plottools:-transform((x,y)->[x,y+1])(plot(min(3,1/x)-1,x=0..1,filled));

You can refer to the global names as :-J and :-F, in order to avoid collision with the locals of the same names.

You can furthermore quote those global name references with uneval quotes, so as to protect against the case of their having been assigned values.

restart;

foo:=proc(A::Matrix)
local J,Q;
J,Q:=LinearAlgebra:-JordanForm(A,output=[':-J',':-Q']);
end proc:

A:=Matrix([[1,2],[3,4]]);

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})

foo(A);

Matrix(2, 2, {(1, 1) = 5/2-(1/2)*sqrt(33), (1, 2) = 0, (2, 1) = 0, (2, 2) = 5/2+(1/2)*sqrt(33)}), Matrix(2, 2, {(1, 1) = 1/2+(1/22)*sqrt(33), (1, 2) = (1/66)*(-3+sqrt(33))*sqrt(33), (2, 1) = -(1/11)*sqrt(33), (2, 2) = (1/11)*sqrt(33)})

 

Download JordanForm_proc.mw

ps. You could sensibly quote the keyword option 'output' as well, on similar grounds.

It's not your fault; there is a bug in the case of filledregions, a specified non-default number of contours, and the new legend mechanism.

I am supposing that you want the specified number of contours (20) as in the first plot below, but the visual look of the thicker color bars in the second plot below.

(I may be able to figure out a hot fix for the procedure, a bit later today...)

restart;

ee:=16.70196911*2^(1/2)*((x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)))^(1/2)
    /(4.373839156*(x^2 + 0.1*y)/((1 - x)*(3*x^2 + 0.2*y)) + 1)^(1/2),
    x = 0.001 .. 1, y = 0.001 .. 1:

opts:=thickness = 0, coloring = ["blue", "yellow"]:

plots:-display(
   plots:-contourplot(ee, contours = 20, opts, legend),
   plots:-contourplot(ee, contours = 20, opts, filledregions),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

plots:-display(
   plots:-contourplot(ee, opts, filledregions, legend),
   legendstyle=[location=right], axes = "boxed", size=[550,500]);

 

Download filled_cont_legend_bug.mw

You are getting bitten by premature evaluation of the call f(x).

The error would occur even if you tried just to compute this,

    f(x);

Either use the functional calling sequence of the plot command, or pass 'f(x)' quoted so as to delay evaluation, or edit procedure f so that it returns unevaluated for nonnumeric x (I haven't done that last one).

restart;

sine :=   plot(sin(x), x=0..4*Pi, color=black,thickness=3):
s    :=   plot(sin(x), x=0..4*Pi, color=red, filled=true):
cosine := plot(cos(x), x=0..4*Pi, color=black,thickness=3):
c      := plot(cos(x), x=0..4*Pi, color=red, filled=true):

f := x -> if cos(x)>0 and sin(x)>0 then
              min(cos(x),sin(x))
          elif cos(x)<0 and sin(x)<0 then
              max(cos(x),sin(x))
          else 0
          end if:

b := plot(f, 0..4*Pi, filled=true, color=green):

plots:-display([sine, cosine, b, s, c]);

 

Download Heck_15.5.mw

If you click on the magenta error message as displayed in the Maple GUI (and if Maple is set to find your web-browser) then it should take you to this related Error Guide page.

[edit] On page 426 of the Heck text (as found by Google) I see the example in question as computing the problematic plot using the functional form, ie.
   b := plot(f, 0..4*Pi, filled=true, color=white):
in the 3rd edition (2003). That happens to coincide with the first way I gave above. It seems as if you have made a mistake, while editing his example.

Change

   Pi(d/2)

to,

   Pi*(d/2)

The former is a functional application of the name Pi to the argument d/2. Presumably you want the multiplication. instead.

In 2D Input you could also use a space before the bracket, to denote so-called implicit multiplication. I find that hard to distinguish, visually.

You can insert the explicit multiplication sign whether in 1D or 2D input mode, and I think doing so is a good idea.
 

restart;

V := (4*Pi(d/2)^3)/3;

(4/3)*Pi((1/2)*d)^3

eval(V, d = 6.35*mm);

(4/3)*Pi(3.175000000*mm)^3

lprint(indets(%,function));

{Pi(3.175000000*mm)}

V := (4*Pi*(d/2)^3)/3;

(1/6)*Pi*d^3

eval(V, d = 6.35*mm);

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

V := 4*Pi*((1/2)*d)^3*(1/3)

(1/6)*Pi*d^3

eval(V, d = 6.35*mm)

134.0663539*mm^3

 

Download multiplication_syntax.mw

It is documented in the Help page with topic coloncolon .

The description from your instructor uses an expression for f. Your attempt calls Newton with an operator for f. Both methodologies can work, but unfortunately your attempt mixed up the two concepts.

Below I show both with modifications of your code, for f as operator or expression.

By the way, you only have to differentiate once. You don't have to repeat that part of the computation, for each iteration of the loop.

You might find these revisions to your code of some use. I corrected the differentiation and evaluation of the derivative, at a point. I also moved the conditional test into the loop so that it would return (possibly earlier) as soon as any iterate satisfied the criterion.

Download rf.mw

restart;
Newton_proc:=proc(f, a)
  local df,n,x1;
  df:=D(f);
  x1:=a;
  if abs(f(x1))<=10^(-8) then
    return x1;
  end if;
  for n to 9 do
    x1:=x1-f(x1)/df(x1);
    if abs(f(x1))<=10^(-8) then
      return x1;
    end if;
  end do;
  return FAIL;
end proc:

Newton_proc( x->x^3-3*x^2+2*exp(x)+5, -1.2 );
         -1.162515305

Newton_proc( x->arctan(x), 1.5 );
              FAIL

restart;
Newton_expr:=proc(f, a)
  local df,n,x,x1;
  x := indets(f,And(name,Not(constant),
                    satisfies(u->depends(f,u))));
  if nops(x)<>1 then
    error "expecting an expression depending on one name";
  else
    x := x[1];
  end if;
  df:=diff(f,x);
  x1:=a;
  if abs(eval(f,x=x1))<=10^(-8) then
    return x1;
  end if;
  for n to 9 do
    x1:=x1-eval(f,x=x1)/eval(df,x=x1);
    if abs(eval(f,x=x1))<=10^(-8) then
      return x1;
    end if;
  end do;
  return FAIL;
end proc:

Newton_expr( x^3-3*x^2+2*exp(x)+5, -1.2 );
          -1.162515305

Newton_expr( arctan(x), 1.5 );
              FAIL

You could simplify the system of equations by the constraint equations, prior to calling solve. (I did this a few hours ago. You can compare with vv's suggestion.)

Download Example_ac.mw

What properties do you know about the variables?

restart;

Given_eq_3_37 := M = k_ * sqrt(L__1 * L__2);

M = k_*(L__1*L__2)^(1/2)

Given_eq_3_30 := k_ = sqrt((L__m)^2 / (L__1 * L__2p));

k_ = (L__m^2/(L__1*L__2p))^(1/2)

combine(eval(Given_eq_3_37,Given_eq_3_30))
  assuming L__1*L__2>0;

M = (L__2*L__m^2/L__2p)^(1/2)

combine(eval(Given_eq_3_37,Given_eq_3_30))
  assuming L__m^2/(L__1*L__2p)>0;

M = (L__2*L__m^2/L__2p)^(1/2)

Download Q20201001_ac.mw

If I understand your goal properly, then one way is to first select all the terms which satisfy
the second condition, and then to select from that those terms which have the least degree.

restart;

F := proc(P)
  local temp, mindeg;
  temp := select(term->member(degree(term,[x])-degree(term,[y]),
                              [0,-1]), [op(P)]);
  mindeg := min(map(degree,temp,[x,y]));
  select(term->degree(term,[x,y])=mindeg, temp);
end proc:

F( 100*x^2*y^2 + 35*y*x + 45*x );

[35*y*x]

F( 13*x^2*y^2 + x*y^2 + 2*y*x^2 );

[x*y^2]

 

Download poly_deg_query.mw

First 107 108 109 110 111 112 113 Last Page 109 of 336