# Items tagged with functionfunction Tagged Items Feed

### How do I express a function as a variable in Maple...

March 31 2014
3 4

I am new user of Maple. I have an expression like f(x,y)/g(x,y) and I want to have Maple name f(x,y) as something simple like "h" so that later equations write h/g(x,y) instead of the complete f(x,y)/g(x,y), and also to be able to simplify other equations in terms of h.

For example, a=(x+1)(y-5)^2/(x+y-3). Can I get Maple to let h=(x+1)(y-5)^2, so that I get h/(x+y-3) when I ask for a?

Sorry if this question is basic (and my math terminology incorrect), but I have been trying for a while.

### A command like fmincon command(matlab) in maple...

March 30 2014
0 2

Hi all

In matlab software we have a command namely fmincon which minimizes any linear/nonlinear algebric equations subject to linear/nonlinear constraints.

Now my question is that: what is the same command in maple?or how can we minimize linear/nonlinear function subject to linear/nonlinear constraints in maple?

thanks a lot

Ph.D Candidate

Applied Mathematics Department

### min piecewise function...

March 30 2014
1 16

Hi all,
I need to find mina(w) then a=-1,0,1 and

w := piecewise((x-a)/t <= -10, 202*a-200*x-(202001/101)*t, (x-a)/t <= -910/101, 3*a-x-(1011/101)*t, (x-a)/t <= 910/101, 2*a-t, (x-a)/t <= 10, a+x-(1011/101)*t, 10 < (x-a)/t, -198*a+200*x-(202001/101)*t)

Also need to plot it, i think it should look like this

Thanks

### plot continuous Piecewise function...

March 20 2014
1 4

Hello fellow maple fans :)

I have tried to plot this continuous Piecewise function

plot(piecewise(0 <= t and t < 2, 2-t, 2 <= t and t <= 3, 2*t-4))

On the interval [0,6]

When i try it plot it it won't show the entre internal, is there a way to tell maple that the funktion should continuous until [0,6]

Please see this http://snag.gy/NPrjG.jpg if you are not sure what i mean in the end it should look like this http://snag.gy/ScgtF.jpg

Greetings David Thanks in advance :)

### problem with system of ode's or maple ?...

March 19 2014
0 2

hi all.
i have a system of ODE's including 9 set of coupled OED's .

i have  converted second deravaties to dd2 , in other words : diff(a[i](t),t,t)=dd2[i](t) . i =1..9 :

and i have set these 9 equations in form of vibrational equations such :  (M.V22)[i]+(K(t).V(t))[i]+P(t)[i] = eq[i] , where M is coefficient Matrix of second  derivatives , V22 is Vector of second derivaties , for example V22[1] = diff(a[1](t),t,t) , and  P(t) is the numeric part of equations ( they are pure number and do not contain any symbolic function ) and K(t).V(t) is the remaining part of equations such that : (K(t).V(t))[i] = eq[i] - (M.V22)[i] - P(t)[i]  , and V(t) are vector of a[i](t)'s which V(t)[1] = a[1](t) ,

i have used step by step time integration method (of an ebook which i have attachted that part of ebook here), when i set time step of solving process to h=0.01 , i can solve this system up to time one second or more, but when i choose h=0.001 or smaller, the answer diverges after 350 steps . i do not know whether the problem is in my ODS system, or maple can not handle this ?the answer about the time t=0.3 are the same in both steps, but after that, the one with stpe time h=0.001 diverges. my friend has solved this in mathematica without any problem, could any body help me ?! it is urgent for me to solve this problem,thnx everybody.

ebook.pdf  step_=_0.001.mw  step_=_0.01.mw

### Problem with piecewise function?...

March 15 2014
2 2

I've been poking around with convolutions on Maple, and some weird behavior came up---if I let it compute the convolution of a piecewise function, then take the convolution of that, it comes out differently than if I enter a function from scratch as the middle step---file attached (PiecewiseProblem.mw).  I'm not really a Maple pro, so am I'm doing something crazy here?

Thanks!

### How does one override Maple's built-in ordering an...

March 13 2014
0 3

I have two equations that are valid under the substitution sin <-> cos, so a simple way to generate the second equation is to replace all occurrences of sin with cos. But Maple gets the wrong answer when I do this, because of its built-in simplification. Here is an example. Z1 and Y1 shows the problem; Z2 and Y2 shows that my attempt to overcome the problem doesn't work.  Z3 doesn't work either, proving that the problem is internally generated by Maple because Maple insists on ordering variables in its own way, no matter how I write them.

________simplified example from Maple 15

restart;
Z1:=sin(-a*x+b);
Z2:='sin(-a*x+b)';
Z3:=sin(b-a*x);

-sin(a x - b)
sin(-a x + b)
-sin(a x - b)
Y1:=subs(sin=cos,Z1);
Y2:=subs(sin=cos,Z2);

-cos(a x - b)
-cos(a x - b)
correct answer should be cos(-a*x+b) but the calculated results are off by a minus sign.

Ans1:=evalf(subs(a=1,b=2,x=3,[Y1,Y2,cos(-a*x+b)]));
[-0.5403023059, -0.5403023059, 0.5403023059]

Question: How do I override Maple's desire to stick the "-" sign outside the sin function?

### Find Trendline and R-squard value from data...

March 10 2014
1 1

Hi

I have some data:

Matrix(10, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = .5, (2, 2) = 3.25, (3, 1) = 1.0, (3, 2) = 5.82, (4, 1) = 1.5, (4, 2) = 7.50, (5, 1) = 2.0, (5, 2) = 8.79, (6, 1) = 2.5, (6, 2) = 9.83, (7, 1) = 3.0, (7, 2) = 10.66, (8, 1) = 3.5, (8, 2) = 11.35, (9, 1) = 4.0, (9, 2) = 11.94, (10, 1) = 4.5, (10, 2) = 12.46})

I want Maple to make a trendline fitting a Logarithmic function. I can make it output some function with this:

LeastSquares(`<,>`(.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5), `<,>`(3.25, 5.82, 7.50, 8.79, 9.83, 10.66, 11.35, 11.94, 12.46), x, curve = a+b*ln(x))

It outputs:

5.96497783539274+4.25309474196387*ln(x)

But please notice, the dataset in the function does not have the first 0 and 0. If i do that:

LeastSquares(`<,>`(0, .5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5), `<,>`(0, 3.25, 5.82, 7.50, 8.79, 9.83, 10.66, 11.35, 11.94, 12.46), x, curve = a+b*ln(x))

It outputs:

Error, (in Matrix) numeric exception: division by zero

Besides that, i need the R-squard value for determinating how well it fits.

If i do the same thing i Excel the data set will give a formular: 5.5464ln(x)-0.2175 with a R-sward value of 0.9985.

How can i do this i maple?

----

Emil Kristensen

### Write a function that takes an integer and a boole...

March 08 2014
0 1

so we have to Write a maple function with -> that takes an integer N and a boolean function

F: {(i,j) l 0<= i,j<= N} -> {true,false}

and returns a list containing all [i,j] such that F(i,j). A procedure that does this
would be

proc(N,F) local i, j, RV;
RV:=NULL;
for i from 1 to N do for j from 1 to N do
if F(i,j) then RV:=RV,[i,j] ; end if ;
end do ; end do ;
return RV ;
end proc ;

The problem is to do this inline, i.e. you have to write
(i,j)-> ...

### How do I generate a 4-D array using a function for...

March 07 2014
1 1

Hi,

I have a 4-D function that I have found an analytic expression for in Maple, but I want to generate a numerical 4-D array, which I can export for use in Matlab. However, I don't think I'm using a very good solution, because it is extremely slow (several minutes for even 10x10x10x10 elements). My code is

NumRange:=10:
NumElements:=10:
dx:=2*NumRange/(NumElements-1):
A:=Array(1..NumElements,1..NumElements,1..NumElements,1..NumElements,[seq([seq([seq([seq(evalf(rho(ws1,ws2,ws1p,ws2p)),ws2p=-NumRange..NumRange,dx)],ws1p=-NumRange..NumRange,dx)],ws2=-NumRange..NumRange,dx)] , ws1=-NumRange..NumRange,dx)],datatype=float);

Rho is an exponential with 10 terms in the exponents.

I also tried using four for-loops but that was even slower!

Thanks for any input

### Remove the "Clarify Expression" pop-up...

March 04 2014
1 6

Hello Maplers, i have encountered a little annoyance with Maple, that i would like to ask, whether it can be solved.

It's when i try to define a function, like f(x)=2x and try to define it with a command f(x):=2x, a pop-up box comes up, asking me whether i'd like to use a 'function definition', or 'remember table assignment', and i would like to make Maple remember my choice that i want a function.

I know i can write it like f:=x->2x, but i hate to look at that, to be frankly..

So, is there any way to solve this?

### Write a function that diagonalises a complex (2x2)...

February 23 2014
0 5

so we have to Write a function that diagonalises a complex (2x2) matrix if possible,

we need the argument to be a (2x2) matrix say A.   and we need the return value to be a list [a1 ;a2 ;b1;b2] of two complex numbers followed by two 2-vectors such that {b1,b2} is a basis for C^2 and so that

Ab1 =a1b1 , Ab2=a2b2  if these exist. if not then the function should return an empty list []

also, the thing is that we're not allowed to load any maple packages, we have to do it by hand :'(

thanks <3

### A straight line in 3D...

February 23 2014
1 4

Dear Maple users,

i have a set of 2 Lines: L1 (determined by the intersection of plane x + y -1=0 and plane x - z - 1=0),

L2 ( intersection of plane x + y-7=0 and plane x-y+1 = 0 ).

which functions or commands of maple should I use "visualize" those 2 lines L1 and L2?

JJ

### Composite Simpson's 3/8 Rule...

February 18 2014
1 3

I am trying to create a procedure that can solve integrals using the Composite Simpson's 3/8 rule. However when I test my procedure against maple's ApproximateInt I am getting the wrong results.

Here is my attempt:

restart;

f:= x -> exp(x)*sin(4*x); # function I am using

simp := proc(a, b, n)
local h, sum, i, single:
h := (b-a)/n:
sum := 0:
single := (3*h/8) * (f(a) + f(b)): # this is the end points
for i from a+h by h to b-h do
sum := sum + (3*h/8) * (3*f(i)):
end do:
print(evalf(sum + single));
end proc:

simp(0,1,12);
0.6224486445
evalf(Student:-Calculus1:-ApproximateInt(f(x), 0..1, method = simpson[3/8], partition=12));

0.5323516717

As you can see my answer is not very close to the answer given by Maple. I am not sure why my procedure simp is wrong.

### How do I solve this system of PDEs in Maple?...

February 13 2014
1 3

Hi there,

I'm quite new to Maple so please forgive me! I have a system of partial differential equations I'm trying to solve in Maple as such below

df/dt = f(1-f) - f * h