# Items tagged with piecewisepiecewise Tagged Items Feed

### approximation by piece-wise constant function ...

June 23 2015
0 2

Hi

I am trying to approximate a function in terms of piece-wise constant function:

$$f(x) = \sum_0^N c_iB_i(x)$$

what modules/packages of maple are helpful here? thanks

### Derivatives of Splines are not defined on some poi...

June 05 2015
1 2

Hello everyone,

I have a question regarding my Spline interpolations. I am not an expert on the theory there, but the maple help tells me that the first derivative of an 3rd degree spline interpolation should exist at the knots. But a derivation returns "undefined" at some of the knots instead. Here is my example:

x(t):=Spline([[0, 0], [1, 1], [2, 2], [3, 2.2], [4, 1.8]],t,degree=3);

returns

x(t):=piecewise(t < 1, .953571428571429*t+0.464285714285714e-1*t^3, t < 2, -0.9286e-1+1.09285714285714*t+.139285714285714*(t-1)^2-.232142857142857*(t-1)^3, t < 3, .65000+.675000000000000*t-.557142857142857*(t-2)^2+0.821428571428571e-1*(t-2)^3, 2.77857-.192857142857143*t-.310714285714286*(t-3)^2+.103571428571429*(t-3)^3);

diff(x(t),t);

returns

piecewise(t < 1., .953571+.139286*t^2, t = 1., Float(undefined), t < 2., .814286+.278571*t-.696429*(t-1.)^2, t = 2., Float(undefined), t <= 3., 2.90357-1.11429*t+.246429*(t-2.)^2, 3. < t, 1.67143-.621429*t+.310714*(t-3.)^2);

Not defined at t=1 and t=2. Is it possible to get an interpolation of which the first derivative exists at every point? Thank you very much!

### Problem on the solution of a linear ODE with a fre...

May 29 2015
1 11

Int(piecewise(t < T1, exp((1/2)*t*(1+2*I-I*sqrt(3))), t < T2, -1000*exp((1/2)*t*(1+2*I-I*sqrt(3)))*(-1/1000+T1-t), T2 <= t, -1000*exp((1/2)*t*(1+2*I-I*sqrt(3)))*(-1/1000-T2+T1)), t)

### ODE- convergence problem...

May 20 2015
0 2

Dear Colleges

I have a problem with the following code. As you can see, procedure Q1 converges but I couldn't get the resutls from Q2.

I would be most grateful if you could help me on this problem.

Sincerely yours

Amir

restart;

Eq1:=diff(f(x),x$3)+diff(f(x),x$2)*f(x)+b^2*sqrt(2*reynolds)*diff(diff(f(x),x$2)^2*x^2,x$1);
Eq2:=diff(g(x),x$3)+diff(g(x),x$2)*g(x)+c*a^2*sqrt(2*reynolds)*diff(diff(g(x),x$2)^2*x,x$1);
eq1:=isolate(Eq1,diff(f(x),x,x,x));
eq2:=subs(g=f,isolate(Eq2,diff(g(x),x,x,x)));
EQ:=diff(f(x),x,x,x)=piecewise(x<c*0.1,rhs(eq1),rhs(eq2));
Eq11:=diff(theta(x),x$2)+pr*diff(theta(x),x$1)*f(x)+pr/prt*b^2*sqrt(2*reynolds)*diff(diff(f(x),x$2)*diff(theta(x),x$1)*x^2,x$1); Eq22:=diff(g(x),x$2)+pr*diff(g(x),x$1)*f(x)+pr/prt*a^2*c*sqrt(2*reynolds)*diff(diff(f(x),x$2)*diff(g(x),x$1)*x^1,x$1);
eq11:=isolate(Eq11,diff(theta(x),x,x));
eq22:=subs(g=theta,isolate(Eq22,diff(g(x),x,x)));
EQT:=diff(theta(x),x,x)=piecewise(x<c*0.1,rhs(eq11),rhs(eq22));
EQT1a:=eval(EQT,EQ):
EQT2:=eval(EQT1a,{f(x)=G0(x),diff(f(x),x)=G1(x),diff(f(x),x,x)=G2(x)}):
bd:=c;
a:=0.13:
b:=0.41:
pr:=1;
prt:=0.86;
reynolds:=12734151.135786774055543653356602;     #10^6;   #1.125*10^8:

c:=88.419896050808975395120916434619:
;
Q:=proc(pp2) local res,F0,F1,F2;
print(pp2);
if not type(pp2,numeric) then return 'procname(_passed)' end if:
res:=dsolve({EQ,f(0)=0,D(f)(0)=0,(D@@2)(f)(0)=pp2},numeric,output=listprocedure);
F0,F1,F2:=op(subs(subs(res),[f(x),diff(f(x),x),diff(f(x),x,x)])):
F1(bd)-1;
end proc;
fsolve(Q(pp2)=0,pp2=(0..1002));
se:=%;
res2:=dsolve({EQ,f(0)=0,D(f)(0)=0,(D@@2)(f)(0)=se},numeric,output=listprocedure):
G0,G1,G2:=op(subs(subs(res2),[f(x),diff(f(x),x),diff(f(x),x,x)])):
plots:-odeplot(res2,[seq([x,diff(f(x),[x\$i])],i=1..1)],0..c);

Q2:=proc(rr2) local solT,T0,T1;
print(rr2);
if not type(rr2,numeric) then return 'procname(_passed)' end if:
solT:=dsolve({EQT2,theta(0)=1,D(theta)(0)=-rr2},numeric,known=[G0,G1,G2],output=listprocedure):
T0,T1:=op(subs(subs(res),[theta(x),diff(theta(x),x)])):
T0(bd);
end proc;
fsolve(Q2(rr2)=0,rr2=(0..100));

shib:=%;
sol:=dsolve({EQT2,theta(0)=1,D(theta)(0)=-shib},numeric,known=[G0,G1,G2],output=listprocedure):
plots:-odeplot(sol,[x,theta(x)],0..c);
#fsolve(Q2(pp3)=0,pp3=-2..2):

Amir

### Constrained solutions for differential equations...

April 25 2015
2 6

Hello! I'm really craving for a piece of advice from you pros.

where

and

Here is solver options with pair of events to get idea about what I want.

Plot of solution

For my purposes it's essential to restrict variables m and D(fi1)(t), D(fi2)(t). While it's very convenient to use piecewise() operator in first case with m, I simply can't find working method for second.

I've tried various events for dsolve, but they trigger only once and I failed to provide continuous restriction on the derivatives in question.

That's what I need in the end:

If there's a way to obtain this result, please, don't make secrets of it :) Thank you in advance!

### 3D plotting of a piecewise...

April 18 2015
1 12

Hi

I have problem with 3Dplotting of this piecewise...can anyone help me please?!

since i know the output will be a value between 0 and 1 can i plot it for different values of Mu in this range to eliminate a dimension?

Mu(x1, x2, x3) = piecewise(or(or(x1 > 55, x2 > 10), y >= 2), 1, x1 < 35 and x2 <= 10 and x3 < 1, (1/10)*x2, and(and(x1 < 35 and x2 <= 10, x3 >= 1), x3 <= 2), max((1/10)*x2, x3-1), and(and(and(x1 >= 35, x1 <= 55), x2 <= 10), x3 <= 1), 1-((55-x1)*(1/20))((10-x2)*(1/10)), and(and(and(and(x1 >= 35, x1 <= 55), x2 <= 10), x3 >= 1), x3 <= 2), max(x3-1, 1-((55-x1)*(1/20))((10-x2)*(1/10))))

Thank you very much in advance...

### discontinue in piecewise function...

March 17 2015
1 1

how can you graph when piecewise function is not continuous?

example:

BB := piecewise (-1.57 < c and c < -1.56, h, -0.06< c and  c < -0.05, aa, -0.5< c and c < 0.04, bb);

### How to get a specific polynomial from a piecewise ...

March 11 2015
1 10

Dear,

I have this code generating a piecewise function:

> with(CurveFitting);

> points := [[0, 1], [1, 2.5], [3, 2.3], [4.2, 5], [5, 3.5], [5.8, 4.2], [7, 7], [8, 10]];

> splcurve := Spline(points, v);

In this particular case I have seven distinct polynomials. Someone knows how could I get one specific polynomial, for example, the one exactly before v < 4.2?

In other terms:

I'd like to define a new function, say 'f', that is exactly the polynomial just before v < 4.2 (e.g, something like f:=(splcurve, v < 4.2)). Do exists this possibility? (I have been looking for it elsewhere but without success!!)

### Showing dashed line for square wave plot...

February 22 2015
1 5

When plotting a continous function that looks something like a square wave, for example like this:

f:=x->piecewise(0<x<Pi,0,Pi<x<2*Pi,Pi);
a:=0: b:=2*Pi: p:=b-a:
fp:=f(x-floor( (x-a)/p)*p);
plot(fp,x=-6*Pi..6*Pi,discont=true);

Is there some way to show dashed vertical lines at the points of discontinuity?

### Plot piecewise continous periodic function...

February 21 2015
0 9

If we have a piecewise continous 2*Pi-periodic function

h(t)=e^(2*t) when 0 < t < 2*Pi

How can we plot it? It should look something like this:

I.e. I want to be able to just set an interval and then it automatically plots the function with the specified periodicity.

### Plotting a function with an arbitrary exponent val...

February 09 2015
1 6

I've got the following piecewise function :

(x^2+y^2)^(alpha).arcsin(y/x) if (x,y) are in [-pi/2,pi/2]

0, (x,y)=(0,0)

1. How do I plot this function taking the alpha variable and the piecewise construct into account?

2. How can I check for points of discontinuity, indifferentiability from the plot/function itself?

### Plotting a function over a range...

January 22 2015
0 2

I've got a piece-wise function(for which I've made the procedure) f defined over x<=-1, -1<x<1 and x>=1 which I am trying to plot over the range of (-2,2). I've tried using plot(f,-2..2) but it doesn't show any curve. Should I add a few more parameters to plot()?

### Maximizing a function...

January 13 2015
0 5

Hi there,

I am trying to maximize a function given a set of values to a parameter in the function. The function is an differential equation belonging to a system of two differential equations.

I have a for loop to state different values to the parameter.

Maple yields the error:

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

When trying to maximize the function.

Supposed that I was doing something wrong in the loop, if I reproduce the contents of the loop outside, and set a value for the parameter. If I plot the solution of the ordinary differential equation, I can see where the maximum lies.

Having plot it, the Optimizamtion:-Maximize works as expected.

However, omitting the plot has a weird effect: I only get the same result depending on the bounds I set for the Maximization:

de1 := diff(A(t), t) = r*m*(1-g)*A(t)-piecewise(t < 8, r*A(t), t >= 8, (r+k)*A(t));
de2 := diff(G(t), t) = r*m*g*A(t)-l*G(t);

ics := A(0) = 25.0, G(0) = 0.;
num := dsolve({de1, de2, ics}, {A(t), G(t)}, type = numeric, output = listprocedure, parameters = [g]);

num(parameters = [g = .15]);
val := eval(G(t), num);

# odeplot(val, [t, G(t)], t = 0 .. 100);

Maximize(val);
Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val2 := Maximize(val);

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val3 := Maximize(val(t), t = 0 .. 60);

[10267.824035766165, [t = 8.25727747134303]]

val4 := Maximize(val(t), t = 0 .. 100);

[6.863211343195069e-9, [t = 59.84184367042171]]

The right answer is [10267.824035766165, [t = 8.25727747134303]]: Why do I get two different answers even if in that range there is only one relative maximum?

I ignore whether the way I am specifying the arguments for the Maximize function is correct. val is a procedure.

What am I missing?

Attached is the worksheet: MaplePrimes_malaria_param_variation_2.mw

Thanks,

jon

### Piecewise command...

November 20 2014
1 2

A function f is defined on R by

f(x):= (1+a|x|)^1/x      , x<0

B                      ,  x=0

ln(1+(a^2)|x|)/x , x>0

where α and β are constants. Investigate whether it is possible to choose α and β so
as to ensure that f is real-valued and continuous at x = 0. Compute any such values
for α and β correct to 10 significant figures. Make use of the piecewise command in
plotting a graph of any resulting continuous function(s) f over the range −20 ≤ x ≤ 20.

I used the help in Maple and manage to get

f = piecewise(x < 0, (1+alpha*abs(x))^(1/x), x = 0, beta, x > 0, ln(1+alpha^2*abs(x))/x)

Not sure about how to compute a and B...

What does it mean by  f is real-valued and continuous at x = 0?

### piecewise function simplify / cancel out a variabl...

October 27 2014
1 3

Hello,
Maple does not cancel out a variable.

Why is that?

Is there a way to solve this?

(I pasted my code on the bottom of this message)

Stephan

restart:
M(x):=piecewise(x<=l,1/2*(q*x^2)/(EI)-3/8*(q*l*x)/(EI),l<x,1/2*(q*x^2)/(EI)-13/8*(q*l*x)/(EI)+5/4*(q*l^2)/(EI)):
M(x):=M(x)*(-EI);
# simplify() does not work.....?
M(x):=simplify(%) assuming EI>0;
# Wiht EI cancelled out by hand it schould look like:
M(x):=piecewise(x<=l,1/2*(q*x^2)-3/8*(q*l*x),l<x,1/2*(q*x^2)-13/8*(q*l*x)+5/4*(q*l^2));

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