## 6071 Reputation

15 years, 216 days

## try/catch...

The try/catch mechanism may be what you are looking for.

 > restart;
 > foo:=proc(n::integer)         print("before internal proc");         proc()                 if n<0 then                         error "something";                 fi;         end proc(); #notice the (); at end         print("after internal proc"); end proc:

Let's try:

 > try foo(3); (a+b)^2;  catch "something": (c+d)^2; end try;

 > try foo(-3); (a+b)^2;  catch "something": (c+d)^2; end try;

 >

If you feel very enthusiastic, you may bundle up the try/catch along with foo
into a signle proc.

 > restart;
 > bar := proc(n::integer)         local foo;         foo:=proc(n::integer)                 print("before internal proc");                 proc()                         if n<0 then                                 error "something";                         fi;                 end proc(); #notice the (); at end                 print("after internal proc");         end proc:         try foo(n); (a+b)^2;  catch "something": (c+d)^2; end try; end proc:
 >

Let's try:

 > bar(3);

 > bar(-3);

## Suggestion...

Your code expresses the essence of the solution, but it can be streamlined a bit.

```restart;
eq := <x, y> =~ lambda*<1, 1> + mu*<1, 2>;
convert(eq, set);
solve(%, {lambda, mu});```

We see that solve() returns a unique solution, indicating that any vector <x,y> may be uniquely represented as a linear combination of <1,1> and <1,2>, indicating that those form a basis for the space.

## EPS and SVG...

Maple's PDF export has been broken in the last several releases. Despite repeated complaints on this forum, no solution seems to be forthcoming.

These two workarounds work quite well on the command-line in Linux.  The equivalent command lines may be available in Mac and Windows but I have neither so I wouldn't know.

1. Workaround #1:  Save the graphics as EPS, let's say filename.eps, then do
epstopdf filename.eps
to produce filename.pdf.
2. Workaround #2:  Save the graphics as SVG, let's say filename.svg, then do
inkscape --export-type=pdf --export-area-drawing filename.svg
to produce filename.pdf.

Both methods produce good quality PDF.  The file size of the PDF file in method #2 is about 1/20 of that of method #1 but the latter is more faithful to the original.

I have attached PDFs cooresponding to
plot3d(x^2+y^2, x=-1..1, y=-1..1);
converted through the two methods.

## Here is the solution...

Here is the solution, but don't just pass it on to your teacher. She won't believe you.

To get an answer with detailed explanation, show what you know and how far you have gotten on your own on this homework.

```restart;
f := x -> (x^3 + 9*x^2 - 9*x - 1) / (x^4 + 1);
numer(D(f)(x) - 1/2);
xvals := fsolve(%, x, maxsols=4);
seq(f(t) + 0.5*(x-t), t in xvals);
plot([f(x), %], x=-7..7, scaling=constrained, color=[seq(cat("oldplots ", i), i=1..5)]);
```

## Does this help?...

```restart;
with(plots):
with(plottools):
p1 := plot(sin(x), x=-2*Pi..2*Pi, color="Red"):
display(
plot(sin(x), x=-2*Pi..2*Pi, color="Green"),
line([-2*Pi,0], [2*Pi,0]),
line([0,-2*Pi], [0,2*Pi])
):
p2 := rotate(%, Pi/4):
display(p1,p2, scaling=constrained);```

I don't see a simple way of adding tickmarks.

## This may be more to your liking...

```restart;
with(plots):
vertices := [
c__1 = <0, -2>,
c__2 = <1, 2>,
c__3 = <2, 2>,
c__4 = <0.5, 6>,
c__5 = <1, 4>
]:
Labels := map( v -> [convert(rhs(v), list)[], lhs(v)], vertices):
display(
textplot(Labels, align={above}),
plottools:-polygon(convert~(rhs~(vertices), list), style=line, color=red)
);
```

## Delay differential equations...

See https://www.mapleprimes.com/questions/229945-Simulation-Of-A-Solution-Of--Neutral for a lot of ideas on how to handle delay differential equations.

## Perhaps this?...

I don't see what you mean by tracing the moving points since the number of point changes in your sequence of plots. Here is how to draw traces of individual moving points that preserve their identities during the motion.

```restart;
with(plots):
f := t -> sin(t);
g := t -> [cos(t), sin(t)];
trace_me := proc(t)
display(
pointplot([t,f(t)], symbol=solidcircle, symbolsize=30, color="Red"),
plot(f(s), s=0..t, color="Green"),
pointplot(g(t), symbol=solidcircle, symbolsize=30, color="Orange"),
plot([g(s)[], s=0..t], color="Blue"),
scaling=constrained);
end proc:
animate(trace_me, [t], t=0..2*Pi);
```

## Solution...

I will illustrate the required procedure in terms of a function that I made up. If this does not work in your case, then you need to provide more details about your function fp(x).

 > restart;
 > with(plots):

Here is a family of function of  defined in terms of a parameter .

 > f := (x,p) -> (x-p)^2 + cos(p);

To calculate the family's envelope, we solve the following system
of two equations for the two unknowns  and .  Call the solution

and .  The envelope is the parametric curve .

 > y = f(x,p), diff(f(x,p),p) = 0; solve({%}, {x,y}): X := unapply(eval(x, %), p); Y := unapply(eval(y, %%), p);

Let us plot the result.  The envelope is shown in blue.

 > display(         seq(plot(f(x,p), x=-10..10, color="Green", view=-1..2), p=-8..8, 0.3),         plot([X(p),Y(p), p=-8..8], color="Blue", thickness=3), size=[700,500]);

We now calculate the area bounded by the central arch of the envelope and the  axis.
From the graph above we see that the arch extends roughly from  to .

To calculate the precise range, we seek parameter values that make

 > p_roots := solve(Y(p), p);

and then calculate the corresponding  values:

 > simplify(X~([p_roots])); evalf(%);

We conclude that the support of the arch is roughly in the range . The corresponding

parameter values are

 > p_roots[1], p_roots[2];

The area bounded by a parametric curve and the  axis is given by :

 > A := simplify(int(Y(p)*D(X)(p), p = p_roots[2] .. p_roots[1]));

 > evalf(A);

## Correction...

You are interpreting Maple's result as if it had said y(x) = whatever.  But that's not what the answer says.  Rather, the answer is an integral with the upper limit as y(x).  The following worksheet shows how to verify that Maple's solution does indeed satisfy the differential equation.

 > restart;
 > ode := diff(y(x), x, x) = - sin(y(x));   # the minus sign is missing in the original worksheet!

 > dsol := dsolve(ode);

Let us verify that dsol[1] is a solution of the ode.  (dsol[2] may be verified in the same way)

 > diff(dsol[1], x); isolate(%, diff(y(x), x)); diff(%, x); applyop(eval, 2, %, %%);

## No real solution...

If we plot the left-hand side and right-hand side expressions of your equation, we see that the plots don't intersect, and therefore there is no (real) solution to your equation.

```eq := exp(x) * (1 + sqrt(1 + exp(-2*x))) - arcsinh(exp(-x)) = x;
plot([lhs(eq), rhs(eq)], x=-3..3);
```

## Solution...

Here is how to go about it.  The resulting figure is not exactly like what you have shown which indicates that your figure was produced based on a different set of parameters than what you have provided.

 > restart;

We have five differential equations:

 > de1 := diff(u__1(y),y,y) + 1/2*diff(N(y),y) + 1/2*theta__1(y) = 0;

 > de2 := diff(N(y),y,y) - 2/3 * (2*N(y) + diff(u__1(y),y)) = 0;

 > de3 := diff(theta__1(y),y,y) = 0;

 > de4 := diff(u__2(y),y,y) + theta__2(y) = 0;

 > de5 := diff(theta__2(y),y,y) = 0;

Find the general solution:

 > dsol := dsolve({de1,de2,de3,de4,de5});

How many integrations constants?

 > indets(dsol, name);

So there are 10 integration constants, which is good since we have 10 boundary and interface conditions.

For now, let us extract the individual solutions of the ODE system:

 > u__1 := 'u__1': eval(u__1(y), dsol): u__1 := unapply(%, y);

 > u__2 := 'u__2': eval(u__2(y), dsol): u__2 := unapply(%, y);

 > theta__1 := 'theta__1': eval(theta__1(y), dsol): theta__1 := unapply(%, y);

 > theta__2 := 'theta__2': eval(theta__2(y), dsol): theta__2 := unapply(%, y);

 > N := 'N': eval(N(y), dsol): N := unapply(%, y);

Now let us look at the boundary condtions.

Boundary conditions on the interval (-1,0):

 > bc[-1] := u__1(-1) = 0, N(-1) = 0, theta__1(-1) = 1,         u__1(0) = u__0, theta__1(0) = theta__0, D(theta__1)(0) = theta_d;

Boundary conditions on the interval (0,1)

 > bc[1] := u__2(1) = 0, theta__2(1) = 0;

Interface conditions at

 > bc[0] := u__1(0) = u__2(0), D(N)(0) = 0, theta__1(0) = theta__2(0),  D(theta__1)(0) = D(theta__2)(0),         D(u__1)(0) + 1/2*N(0) = 1/2*D(u__2)(0);

Apply the 10 boundary and interface conditions to determine the 10 integration coefficients:

 > c_vals := solve({bc[-1], bc[0], bc[1]});

Evaluate u1 and u2

 > my_u1 := eval(u__1(y), c_vals); my_u2 := eval(u__2(y), c_vals);

 > plots:-display(         plot(my_u1, y=-1..0, color=red),         plot(my_u2, y=0..1, color=blue) );

## Here is what you really should be asking...

As I noted earlier, your equation is linear, so your focus on nonlinear equations is out of place. If you refer to the discussion of linear first order equations in your differential equations textbook, you will find a general solution obtained through the method of integrating factors. The transient and steady-state parts of the solution may be extracted from there.

What you should be asking is: What do the transient and steady-state solutions look like? I have attached a PDF in which I have analyzed a slightly more general differential equation than the one that you have asked about. In the following worksheet I use the results obtained in that PDF to calculate and plot the transient and steady-state graphs for your equation. Note that this has nothing to do with nonlinear equations.

 > restart;
 > with(plots):

In the attached PDF I have analyzed the following first order linear equation:

 > diff(x(t),t) = p(t) - (a + q(t))*x(t);

Assumption:

 • p(t) and q(t) are bounded periodic functions of some period, say σ.
 • the average of q(t) over a period is zero
 • a > 0 is a constant.

Define

 > Q(t) = Int(q(s), s=0..t);

It is evident that Q is σ-periodic and Q(0) = 0.

In the attached PDF I show that the solution x(t) subject to an initial condition x(0)=x_0

tends to a σ-periodic steady state as time goes to infinity.  The transient and steady state

parts of the solution are given by:

 > x__tr(t) = x__0*exp(-a*t-Q(t)); x__ss(t) = Int(p(t-s)*exp(-a*s - Q(t) + Q(t-s)), s=0..T);

where the constant T is a sufficiently large time value beyond which

the transient may be considered as died out.

 >

A concrete example

 > de := diff(x(t),t) = 1 - ( 1 + sin(10*t)/10) * x(t), x(0) = 0.9;

This corresponds to the choices of p(t) = 1, q(t) = sin(10*t)/10, and a = 1. We calculate Q:

 > int(sin(10*s)/10, s=0..t): Q := unapply(%, t);

Let us solve the differential equation numerically by applying Maple's dsolve():

 > dsol := dsolve({de}, numeric);

and graph it:

 > p__exact := odeplot(dsol, t=0..10, color=red);

We calculate the transient from equation (4a) in the attached PDF and plot it:

 > x__tr := 0.9*exp(-t-Q(t));

 > plot(x__tr, t=0..10);

We see that the transient dies out at about T=7, beyond which the solution

goes into steady-state. The steady-state is given in equation (4b) in the PDF:

 > x__ss := Int(exp(-s-Q(t) + Q(t-s)), s=0..7);

and here is what it looks like:

 > p__ss := plot(x__ss, t=0..10, color=blue);

Let's plot the exact solution and the steady-state together to verify

that they match:

 > display(p__exact, p__ss);

 >

## You have two solutions...

Your equation has two solutions, and therefore sol produced by maple consists of two parts:

`sol := {solution1}, {solution2}`

In your code, you are attempting to convert sol to Matlab() and that backfires.  You need to pass the individual solution1 and solution2 to Matlab():

```Matlab(sol[1][]);
Matlab(sol[2][]);```

The purpose of the empty brackets is to remove the curly braces in sol.

## Not a triangle...

The "triangle" that you have depicted is not a spherical triangle since the blue edge is not an arc of a great circle, and therefore the Pythagorean Theorem does not apply.

Aside: You have not shown your calculations, so I calculated everything from scratch.  My calculation shows that the length of the green curve is

which evaluates to 0.9228460424.

 1 2 3 4 5 6 7 Last Page 2 of 44
﻿