Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2014-02-22 14:32:39

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Integrating a piecewise function with Maxima

I wanted to integrate this function

I've tried the following but as you can see, it does not work.

(%i1) f(x) := if x>0 then sin(x) else 0$

(%i2) integrate(f(x),x,-%pi,%pi);
                     %pi
                    /
                    [
(%o2)               I      (if x > 0 then sin(x) else 0) dx
                    ]
                    /
                     - %pi

What to do?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#2 2014-02-22 15:00:36

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

Hi Agnishom;

I have no idea how to do this, but you could do the following:

romberg(if x>0 then sin(x) else 0, x, -%pi, %pi);

or perhaps

quad_qags(if x>0 then sin(x) else 0, x, -%pi, %pi);

They integrate the function numerically rather than analytically.

Or better yet, try Mathematica


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#3 2014-02-22 15:17:11

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Why not just integrate sin(x) between 0 and π?

In geogebra it is done like this.

f(x)=If[x<0,0,1]
g(x)=If[x>=0,1,0]
Integral[f,1,2]
Integral[g,1,2]


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#4 2014-02-22 16:05:04

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

I tried that but still there are too many 'too many context' errors, also the integration does not work fine.

So, you are an expert geogebra user now.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#5 2014-02-22 16:25:05

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Integrating a piecewise function with Maxima

Example in Sage:

f1(x) = 1
f2(x) = 1-x
f3(x) = x^2-5
f = Piecewise([[(-oo,0),0],[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,oo),0]])
integrate(f,x,-oo,oo)

= 11/6


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#6 2014-02-22 16:32:29

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

Sage is very powerful. But it is too huge a download.

What does oo mean?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#7 2014-02-22 20:56:38

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Infinity probably.

I can handle geogebra. You will have to find a way to have M around all the time.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#8 2014-02-22 21:10:48

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

You will have to find a way to have M around all the time.

Why?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#9 2014-02-22 21:12:03

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Hmmm, how can you follow what I am posting if we speak different languages?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#10 2014-02-22 21:51:37

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Integrating a piecewise function with Maxima

Sage is very powerful. But it is too huge a download.

That's true, around 4 GB after decompressing, takes more space than some linux distro installations!
Anyway, you may be having a friend with unlimited data usage plan to download it for you.

What does oo mean?

it's infinity. You may use the full form also

integrate(f,x,-infinity,infinity)

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#11 2014-02-22 22:29:15

anonimnystefy
Real Member
From: Harlan's World
Registered: 2011-05-23
Posts: 16,049

Re: Integrating a piecewise function with Maxima

bobbym wrote:

Hmmm, how can you follow what I am posting if we speak different languages?

We already found that that can be quite a problem.


“Here lies the reader who will never open this book. He is forever dead.
“Taking a new step, uttering a new word, is what people fear most.” ― Fyodor Dostoyevsky, Crime and Punishment
The knowledge of some things as a function of age is a delta function.

Offline

#12 2014-02-22 23:42:06

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Integrating a piecewise function with Maxima

You will have to find a way to have M around all the time.

Install a native linux in a phone (Ubuntu touch is on its way), and use ARM version of the software! Then can be used with a remote login.


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#13 2014-02-23 03:45:03

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

gAr wrote:

You will have to find a way to have M around all the time.

Install a native linux in a phone (Ubuntu touch is on its way), and use ARM version of the software! Then can be used with a remote login.

I do not have a smartphone sad

ARM version of which software? There is a android version of Maxima. Also, why Ubuntu Touch? Ain't Android a linux already?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#14 2014-02-23 06:04:56

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Hi Agnishom;

What you could try is using your Windows machine with your CAS when you are on MIF. If you are worried about security then do not go anywhere else while on Windows. When you are finished here then you can reboot and start Linux.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#15 2014-02-23 06:13:02

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Integrating a piecewise function with Maxima

I do not have a smartphone

Me neither! Just telling.

ARM version of which software?

Anything that you wanted to use. Did you know that you can get free Mathematica with Raspberry Pi?

Also, why Ubuntu Touch? Ain't Android a linux already?

Android is linux with Java bloat, owned by morons in or*cle! And to use its applications, you need to trade your identity with g**gle. Now they have billions of identities to give to the governments.

You can use ubuntu touch just like the desktop version. You can even have the terminal applications running, and all the repository is available to the phone also. Though I'm not sure whether they have all the packages for ARM architecture also.


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#16 2014-02-23 13:16:17

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

Hi bobbym;

Do not worry. I'll be able to run any M command you give within 12 hours whenever needed. And since the forum is not an instant chat cafe, this delay is okay.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#17 2014-02-23 15:49:18

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

That is very long when we are working on something together. But if that is all you have then it will have to be enough.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#18 2014-02-23 17:07:43

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

OK, I will be near my M when we are working on something.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#19 2014-02-23 17:52:06

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Do you know that a Fourier series can also help sum another series?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#20 2014-02-23 21:24:07

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

No, and I do not see how a Fourier series is useful.


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#21 2014-02-23 22:19:04

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

The graphs should be showing you that they are useful to approximate other functions.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#22 2014-02-27 02:01:26

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

I beg your pardon?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#23 2014-02-27 02:02:56

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Agnishom wrote:

No, and I do not see how a Fourier series is useful.

bobbym wrote:

The graphs should be showing you that they are useful to approximate other functions.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#24 2014-02-27 02:11:47

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Integrating a piecewise function with Maxima

Why should that be useful?

May I ask you a different question about M usage?


'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'
'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'
I'm not crazy, my mother had me tested.

Offline

#25 2014-02-27 02:16:37

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Integrating a piecewise function with Maxima

Because after polynomials, trig terms are the next easiest to compute. So it just natural that we would want to approximate difficult functions with bunches of easier ones.

May I ask you a different question about M usage?

Hmm, what question? And maybe you should make a new thread for it.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

Board footer

Powered by FluxBB