acer

30152 Reputation

29 Badges

18 years, 232 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

You don't actually need to assign to locals DV,RV1,RV2 inside the procedure. You could simply utilize the parameters DVA,RV1A,RV2A instead. Your choice.

At least one of your worksheets (you had multiple attachments, apparently duplucates...) has at least one instance of hidden characters, making the statement with the RV1 assignment not as it appeared.

" restart: with(plots):with(DEtools):with(Student[ODEs]):infolevel[Student]:=3 ;"

3

DV := y(x)*diff(y(x), x) = exp(x);

y(x)*(diff(y(x), x)) = exp(x)

RV1 := y(1) = 1;
RV2 := y(1) = -1;

y(1) = 1

y(1) = -1

opl_1 := dsolve({DV, RV1}, y(x));

y(x) = (2*exp(x)-2*exp(1)+1)^(1/2)

opl_2 := dsolve({DV, RV2}, y(x));

y(x) = -(2*exp(x)-2*exp(1)+1)^(1/2)

opl := plot({rhs(opl_1), rhs(opl_2)}, x = 0 .. 5, y = -10 .. 10, thickness = 3)

lijnelement := dfieldplot(DV, y(x), x = 0 .. 5, y = -10 .. 10, title = "lijnelementveld met intergaalkromme door (1,1)(1,-1)")

display({opl, lijnelement}, size = [500, 400])

restart

DVplot:=proc(DVA,RV1A,RV2A)
          local DV,RV1,RV2,opl_1,opl_2,opl,lijnelement;
          DV := DVA;
          RV1 := RV1A;
          RV2 := RV2A;
          opl_1 := dsolve({DV, RV1}, y(x));
          opl_2 := dsolve({DV, RV2}, y(x));
          opl := plot({rhs(opl_1), rhs(opl_2)}, x = 0 .. 5, y = -10 .. 10, 'thickness' = 3);
          lijnelement := DEtools:-dfieldplot(DV, y(x), x = 0 .. 5, y = -10 .. 10,
                                             'title' = "lijnelementveld met intergaalkromme door (1,1)(1,-1)");
          plots:-display({opl, lijnelement}, _rest);
end proc:

DVA := y(x)*(diff(y(x), x)) = exp(x)

y(x)*(diff(y(x), x)) = exp(x)

RV1A := y(1) = 1

y(1) = 1

RV2A := y(1) = -1

y(1) = -1

DVplot(DVA, RV1A, RV2A, size = [500, 400])

NULL

Download DV_plotten-_procedure_ac.mw

[edit] Earlier I wondered why you didn't use DEplot. But now I see that your explicit symbolic solution makes it easier to handle the left-endpoint.

 

pow := x -> x^op(1,procname):

pow[3](7);

             343
pow[4](1.1);

            1.4641

pow[3/2](1.1);

         1.153689732

One problem with evalf(...,n) is that it can be confusing to some users when the first argument is a name that has been assigned a sequence.

The evaluation rules of evalf keep that sequence from being flattened before evalf receives them.

It keeps things more clear to use evalf[n] intead.

A made-up example:

restart;

 

L := Int(sin(x)/3,x=0..Pi), 13;

Int((1/3)*sin(x), x = 0 .. Pi), 13

The intent and behavior here is clear.

evalf[ L[2] ]( L[1] );

.6666666666667

This also gets the same effect, but when evalf(...,n)
was documented then some people would get surprised
that the final example doesn't get this same result.

evalf( L[1], L[2] );

.6666666666667

Some people might mistakenly expect the following
to use 13 digits of working precision while computing
only the numeric integral.

But instead it does floating-point computation of each
entry in sequence L, at default 10 Digits.

evalf( L );

.6666666667, 13.

Download evalf_seq_ex.mw

For backwards compatibility evalf(...,n) still works. But it seems more user-friendly to only document the less potentially confusing syntax.

 

restart;

r := Vector[row](3, symbol=R);

Vector[row](3, {(1) = R[1], (2) = R[2], (3) = R[3]})

c := Vector(3, symbol=C);

Vector(3, {(1) = C[1], (2) = C[2], (3) = C[3]})

c.r;

Matrix(3, 3, {(1, 1) = C[1]*R[1], (1, 2) = C[1]*R[2], (1, 3) = C[1]*R[3], (2, 1) = C[2]*R[1], (2, 2) = C[2]*R[2], (2, 3) = C[2]*R[3], (3, 1) = C[3]*R[1], (3, 2) = C[3]*R[2], (3, 3) = C[3]*R[3]})

(c.r)^%T

Matrix(3, 3, {(1, 1) = C[1]*R[1], (1, 2) = C[2]*R[1], (1, 3) = C[3]*R[1], (2, 1) = C[1]*R[2], (2, 2) = C[2]*R[2], (2, 3) = C[3]*R[2], (3, 1) = C[1]*R[3], (3, 2) = C[2]*R[3], (3, 3) = C[3]*R[3]})

with(LinearAlgebra):

OuterProductMatrix(r,c);

Matrix(3, 3, {(1, 1) = C[1]*R[1], (1, 2) = C[2]*R[1], (1, 3) = C[3]*R[1], (2, 1) = C[1]*R[2], (2, 2) = C[2]*R[2], (2, 3) = C[3]*R[2], (3, 1) = C[1]*R[3], (3, 2) = C[2]*R[3], (3, 3) = C[3]*R[3]})

OuterProductMatrix(r,c)^%T;

Matrix(3, 3, {(1, 1) = C[1]*R[1], (1, 2) = C[1]*R[2], (1, 3) = C[1]*R[3], (2, 1) = C[2]*R[1], (2, 2) = C[2]*R[2], (2, 3) = C[2]*R[3], (3, 1) = C[3]*R[1], (3, 2) = C[3]*R[2], (3, 3) = C[3]*R[3]})

Download OPM.mw

You didn't state whether you were using the numeric option of dsolve.

I'll give an example of a system solution both without and with the numeric option.

For the symbolic solution you can plot the solutions using either expressions or operators (constructed using unapply). I show both. For the numeric solution you can use odeplot (or plot the operators that I obtain).

restart;

>

 

ode := diff(f(x),x,x) = -f(x), diff(g(x),x)=g(x)-2*f(x);

diff(diff(f(x), x), x) = -f(x), diff(g(x), x) = g(x)-2*f(x)

ics := f(0)=0, D(f)(0)=1, g(0)=1;

f(0) = 0, (D(f))(0) = 1, g(0) = 1

Sans := dsolve({ode, ics}, {f(x),g(x)});

{f(x) = sin(x), g(x) = sin(x)+cos(x)}

fexpr := eval(f(x),Sans);
gexpr := eval(g(x),Sans);

sin(x)

sin(x)+cos(x)

plot([fexpr, gexpr], x=0..2*Pi);

eval( [fexpr,gexpr], x=Pi/3 );

[(1/2)*3^(1/2), (1/2)*3^(1/2)+1/2]

Sf := unapply(fexpr,x);

proc (x) options operator, arrow; sin(x) end proc

Sg := unapply(gexpr,x);

proc (x) options operator, arrow; sin(x)+cos(x) end proc

plot([Sf, Sg], 0..2*Pi);

[Sf(Pi/3), Sg(Pi/3)];
evalf(%);

[(1/2)*3^(1/2), (1/2)*3^(1/2)+1/2]

[.8660254040, 1.366025404]

Sf(x), Sg(x);

sin(x), sin(x)+cos(x)

Fans := dsolve({ode, ics}, {f(x),g(x)}, numeric, output=listprocedure):

plots:-odeplot(Fans, [[x,f(x)],[x,g(x)]], x=0..2*Pi, size=[600,200]);

Ff := eval(f(x),Fans):

Fg := eval(g(x),Fans):

[Ff(Pi/3), Fg(Pi/3)];

[HFloat(0.8660254938907389), HFloat(1.3660255551127731)]

 

Download ds_func_ex.mw

You can also read the documentation.

restart;

expr:=exp(2*a);

exp(2*a)

 

The following does a structural change. And the result displays
differently, accordingly and not just as some typesetting effect.
(This Question originally had the `typesetting` tag.)

 

G := expand(expr);

(exp(a))^2

 

The two expressions can behave differently, in particular under
arithmetic operations.

 

indets(expr);

{a, exp(2*a)}

indets(G);

{a, exp(a)}

expr/exp(a);

exp(2*a)/exp(a)

G/exp(a);

exp(a)

 

There are other operations which do not normally "see" that
exp(2*a)=exp(a)^2.

 

factor( exp(2*a)+2*exp(a)+1 );

exp(2*a)+2*exp(a)+1

factor( expand( exp(2*a)+2*exp(a)+1 ) );

(exp(a)+1)^2

 

You can control what does or does not get expanded.

 

expr2 := sin(x+y) + exp(2*a);

sin(x+y)+exp(2*a)

expand( expr2 );

sin(x)*cos(y)+cos(x)*sin(y)+(exp(a))^2

expand(expr2, exp(2*a) );

sin(x)*cos(y)+cos(x)*sin(y)+exp(2*a)

This one is like an example on the expand Help page.

expand(expr2, op(indets(expr2,specfunc(exp))) );

sin(x)*cos(y)+cos(x)*sin(y)+exp(2*a)

frontend(expand, [expr2], [{`+`,trig}]);

sin(x)*cos(y)+cos(x)*sin(y)+exp(2*a)

 

The behavior is not restricted to just exp.

 

expr3 := t^(2*a);

t^(2*a)

expand( expr3 );

(t^a)^2

combine( % );

t^(2*a)

combine( expand( expr ) );

exp(2*a)

 

The ability to forcibly change the structure in such ways is
fundamentally useful to symbolic programming.

 

Download expand_exp_notes0.mw

Does this serve your purpose?

restart;

ode1:= diff(c(T),T)=-2*c(T)*(1+beta__c*c(T)^2/p__c(T)^2):
ode2:= diff(p__c(T),T)=2*(1+beta__c*c(T)^2/p__c(T)^2)*p__c(T):

alt:=map(solve,eval([dsolve(eval([ode1,ode2],[p__c(T)=P__c(T)*beta__c]),
                            [c(T),P__c(T)],'explicit')],
                    [P__c(T)=p__c(T)/beta__c]),
         {p__c(T),c(T)});

[{c(T) = -2*2^(1/2)*(c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = -((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = 2*2^(1/2)*(c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = -((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = -2*2^(1/2)*(c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = ((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = 2*2^(1/2)*(c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = ((1/2)*I)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = -2*(-2*c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = -(1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = 2*(-2*c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = -(1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = -2*(-2*c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = (1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}, {c(T) = 2*(-2*c__2*beta__c/(2*c__1*(exp(T))^8+16*c__2)^(1/2))^(1/2), p__c(T) = (1/2)*(8*c__1*(exp(T))^8+64*c__2)^(1/4)*beta__c}]

map(X->odetest(X,[ode1,ode2]),alt);

[[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]

Download ode_sc.mw

 

Yes, one way to see that this is automatically simplified is to
observe that it occurs even if evaluation is delayed via quotes.

 

Automatic simplification occurs between parsing and evaluation.

 

'[a,b]/2';

[(1/2)*a, (1/2)*b]

 

Your second example did not automatically act across the list
because the factor was not of type numeric.

[a,b]/exp(2);

[a, b]/exp(2)

 

You can avoid the hammer of an expand call by dividing elementwise.

 

[a,b]/~c;

[a/c, b/c]

Download list_auto_ex.mw

What do you think it means to integrate w.r.t. y an expression containing both y and y[1]?!

Try changing y[1] to something like y1 or y__1, if you intend it to be wholly independent of y the variable of integration.

[edit] It should be obvious that this applies to y[2] as well, or any other indexed instance of the variable of integration. It doesn't make sense at all to have such present in the integrand.

In my Maple 2024 GUI preferences file I have this item:

ScrollableMathTableOutput=false

and I don't get the scrollable Matrix display.

Here's an example of using Statistics:-NonlinearFit on your problem.

FindOptimizedParametersFit_ac.mw

Here are some ways to get just that one result.

nb. The OP did not tell us explicitly whether he wanted only real solutions, though he did try RealDomain as well as the assumption x>0.

restart;

eqx := x^(3/2) = a;

x^(3/2) = a

solve({eqx,a>-infinity},x);

{x = a^(2/3)}

PDEtools:-Solve({eqx,a>-infinity},x);

{x = a^(2/3)}

RealDomain:-solve(eqx,{x});

{x = a^(2/3)}

solve({eqx,Or(a<0,a>0)},x) assuming Or(a<0,a>0);

{x = a^(2/3)}

Download solve_par_real.mw

The functionality for alternate spellings of keyword parameters is available syntax.

It is documented on the Help page for topic parameter_processing.

See below, the parameter declaration,
   {[color,colour]:="b"}
in the definition of the procedure assigned to name foo.
 

restart

coltest:=proc(c)
  if c="b" then return 1
   elif c="r" then return 2
   elif c="g" then return 3
  end if;
end proc:

 

foo:=proc(a,{[color,colour]:="b"})
local COL;
   COL:=coltest(colour);
if COL=1 then return a
  elif COL=2 then return a^2
  elif COL=3 then return a^3
  else error `wrong colour`;
end if ;
end proc:

 

foo(3,colour="r")

9

foo(2,colour="p")

Error, (in foo) wrong colour

foo(3,color="r")

9

foo(2,color="p")

Error, (in foo) wrong colour

Download 2024-03-21_Q_colour_or_color_ac.mw

I also added a linebreak after the caption of the first plot, to give a little more space between the plot and what follows below it. I made the two slightly different so that you could choose what aspects you'd prefer.

I also set the size, and reduced the vertical view. (Change back, if unwanted.)

I got rid of the y-axis by setting its color to white. If you actually want all 4 edges of the boxed axes -- but not any y-ticks, say -- then please describe the effect you're after explicitly.

NULL

restart

with(Statistics)

NULL

A := [521, 383, 249, 238, 200, 146, 136, 135, 124, 123, 113, 113, 109, 106, 105, 95, 83, 82, 73, 69, 63, 45, 31, 30, 26, 18]

B := [1620, 521, 383, 249, 238, 200, 146, 136, 135, 124, 123, 113, 113, 109, 106, 105, 95, 83, 82, 73, 69, 63, 45, 31, 30, 26, 18]

BoxPlot([A], title = `#ms("Population density",mathcolor="blue");`, deciles = false, orientation = horizontal, width = .1, view = [0 .. 600, 0 .. .12], titlefont = [Tahoma, bold, 14], caption = typeset(`#ms("People per square km",mathcolor="red");`, "\n"), captionfont = [Tahoma, bold, 12], color = "Spring_Blue", mean = false, axis[2] = [color = "white"], axes = normal, size = [600, 300])

BoxPlot([B], title = `#ms("Population density",mathcolor="blue");`, deciles = false, orientation = horizontal, width = .1, view = [0 .. 1630, 0 .. .12], titlefont = [Tahoma, bold, 14], caption = `#ms("People per square km",mathcolor="red");`, captionfont = [Tahoma, bold, 12], color = "Spring_Blue", mean = false, size = [600, 300])

 

 

Download S5StatBoxPlotBtest_ac.mw

The Tabulate command will place its results in a (Task) region that appears below the normal output region of an Execution Group (or Document Block).

When called from within a procedure, a Tabulate call can be used something a bit like a print/lprint call, in the sense that it can be done before the return from the procedure.

2024-03-18_Q_Format_Returned_Results_into_a_Table_ac.mw

nb. If you make two or more Tabulate calls in a single Execution Group then the last will clobber the earlier. So you may well want to keep your calls to your procedure (as you already have them) in their own separate Execution Groups.

3 4 5 6 7 8 9 Last Page 5 of 313