# Items tagged with piecewisepiecewise Tagged Items Feed

### Piecewise Function...

Yesterday at 1:05 AM
1 4

Piecewise function in Maple are continuous function. Now, how I able to write the commands for following discontinuous piecewise function?

and when find out f(0) the result is undefined?

### Problem with plot...

November 23 2015
0 1

In this code, plot() and Norm() fail when used over a piecewise() function:

Error, invalid input: VectorCalculus:-Norm expects its 1st argument, v, to be of type {Matrix, Vector}, but received piecewise(t < 0, Vector[row](2, {(1) = -1, (2) = 0}, attributes = [coords = cartesian]), Vector[row](2, {(1) = 1, (2) = 0}, attributes = [coords = cartesian]))

Note that the same Norm() and piecewise() work fine when used without the plot() function:

Norm(vec(1));
1

Code works fine when piecewise() is removed, leaving a plot() / Norm() combination, for example:

So only the simultaneous combination plot() / Norm() / piecewise() fails.

Finally, the question is:

Is there a way to plot Norm() / piecewise() combinations without workarounds like intermediate PLOT structures?

Thank you

### How can I get a table of solution ...

November 19 2015
0 10

with small step rather than two points?

I had writen my questions into this code hw2_finished.mw And I think there's maybe something wrong with A=[0..130]

I think you can understand what I want by reading this code but if you are confused please let me know.

### Problem with integral in dsolve...

November 17 2015
0 6

This is the code  hw2_final.mw

Let me explain it.

I am sure that the mistakes must be about the expresstion of the I1(t) and I2(t). Actually if you delete I1(t) and I2(t) , the whole code works and get the picture at the bottom.

What I want is to put the expresstion of the I1(t) and I2(t) into 'sol:=dsolve...' and 'plots...' to get the picture of I1(t) and I2(t) with respect to t. Before the t* which subject to Phi(t*)=0 (The blue line in the picture at the bottom is Phi) I want I1(t) and after t* I want I2(t).

I1(t) = (int(sqrt(2*(H(t)+omega*cos(q(t)))), q(t) = q(t)-2*Pi .. q(t), numeric))/Pi.    what I want of this experesstion is to get  'int(sqrt(2*(H(t)+omega*cos(q(t)))' from  'q(t)-2*Pi' to 'q(t)' by numeric method.This q(t) is the solution of the ODE sys.

For example(the number I used is not true,just for example) , at the point t=20, q(t)=30-2*Pi.

so I1(t)= (int(sqrt(2*(H(t)+omega*cos(x))), x = 30-2*Pi .. 30, numeric))/Pi.The I2(t) I want is similar to I1(t).

How can I solve it?

### How to map a piecewise?...

November 12 2015
2 5

Hello,

I use a map() command to get the values of function for each element of vector. Here is an example of a simple task:

restart:

A:=[1,2,8];

f1:=x->2*x;
f1_table_A:=Vector([map(f1,A)]);

I would like to do the same with piecewise function but it doesn't work. Here is an example:

restart:
with(plots):
f:=2*x:
g:=x^2:

h:=x->piecewise( 0<=x and x<= 5, f, 5<x and x <= 10, g ) ;
A:=[1,2,8]:
h_table_A:=map(h,A):

Is it possible to work with piecewise function? Maybe someone has an idea how to do it in different way?

Kind regards,

Iza

### Error when executing procedure...

November 04 2015
1 2

Hello,

I'm writing a code and I seem to have an issue when trying to implement a procedure. Here is the code:

 >
 >
 >
 >
 >
 >
 >
 >
 (1)
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >

Any help would be greatly appreciated.

Gambia Man

### Error in Distribution...

October 17 2015
0 2

Hi,

I have the following input

***

restart;
with( Statistics ):

a:=2;c:=0.3;
g:= exp(-a*x) + c*a*exp(-a*x);
#f := x -> piecewise( x < 0, 0, x>0, g );
f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

norm_factor:=int( f(x), x=0..infinity );
print(norm_factor);

randomize():
F := Distribution( PDF = 1/norm_factor*f ):
X := RandomVariable( F ):

N := 20;
S := convert( Sample(X,N), list );

print(cc,S[1]);

***

The code works. However, if I comment out

f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

, then use

f := x -> piecewise( x < 0, 0, x>0, g );

i.e.

f := x -> piecewise( x < 0, 0, x>0, g );
#f :=x -> piecewise( x < 0, 0, x>0, exp(-a*x) + c*a*exp(-a*x));

It is said "

Error, (in Statistics:-Sample) unable to construct the envelopes for _R, try to specify the initial range"

The norm_factors are actually the same for both inputs. What is the reason for the error message?  Suppose I still want to use something like

f := x -> piecewise( x < 0, 0, x>0, g );

,how to fix the problem?

Thank you very much

### Slow and not accurate...

September 07 2015
1 9

restart: with(plots):
H := a -> piecewise(a>=0,1):
f1 := y->(H(y-1*Pi)-H(y-2*Pi))*sin(y)^2:

g1:=(f1(y)/sqrt(4*Pi*t))*(sin((x-y)^2/4/t+Pi/4)-sin((x+y)^2/4/t+Pi/4)):
g2:= int(g1, y= 0..100):

g3:= diff(g2,t):
g4:= diff(g2,x$2): g5:= (g3^2+g4^2)/2: E2:= unapply(Int(g5, x= 0..100, epsilon= 1e-4, digits= 7), t): CodeTools:-Usage( plot(E2, 0..20, numpoints= 50, labels= [t, E])); The above mentioned code should give constant figure, but it takes a lot of time and not accurate. If you can help me to improve these codes, I would be pleased. Thanks! ### Derivative of Spline at the nodes... August 12 2015 2 4 Hi! This question is related to http://www.mapleprimes.com/questions/204419-Derivatives-Of-Splines-Are-Not-Defined and http://www.mapleprimes.com/questions/42114-Problem-With-Spline-Integrating , however I have not been able to apply the solutions given there to my problem. I have a set of points given by and certain function value points given by where e1 is the function I am approximating. Using I come up with my piecewise function. When I do diff(e4,x), however, the points at the nodes show "float(undefined) x=0.2..."(the node). As it turns out, the value of the derivative on the left of the node is not equal to that of the right side by a factor of 10^(-7), in other words, numerically unimportant but high enough for maple to realise it is not the same number. How could I tell Maple that I am happy choosing, for example, the value given by the function on right side of the node? I welcome any suggestions. Many thanks in advance. ### How to compute PDF?... July 12 2015 2 1 I am trying to find the pdf of the inverse of a random variable X, that represents a distribution I defined. I currently have : with(Statistics): T:=Distribution(PDF=(x->piecewise(0<x and x<1,1/4,3<x and x<5,3/8,0))); X:=RandomVariable(T); PDF(X,u); CDF(X,u); Y:=1/X; T1:=RandomVariable(Y); but this seems to be incorrect as I get a message saying T1:=RandomVariable(Y) is being passed a wrong argument. What is the right way to obtain the pdf of 1/X? ### 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!

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