Message Boards Message Boards

0
|
6313 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

speed up a code in mathematica.

Posted 10 years ago

Professionals Hi, I wrote a program as follows. It takes a long time to answer. After two hours of running still does not answer. in the main program mm = nn = 30 that It takes so much more. Please help me. many thanks.

Attachments:
POSTED BY: esi fn
5 Replies

The final "diagonal" variable looks looks like it would cause an underflow if evaluated. (It has 1 + E^(1.5625*10^22 (-...)) in the denominator.)

POSTED BY: Marvin Ray Burns

A suggestion: that you work your way away from coding in a traditional procedural approach and recast your problems in more Mathematica-like functional, pattern-matching, Symbolic, and other paradigms. You will achieve much greater clarity and brevity, and you will learn the "way of Mathematica".

POSTED BY: David Reiss
Posted 10 years ago

@Marvin Burns i think main problem is in integrate part of code. how can i speed up integration in mathematica.

POSTED BY: esi fn

You should take a look at your various expressions along the way for a simplified version of your code: e.g. for

nn = 2;
mm = 2;

or even

nn = 1;
mm = 1;

Here is the value of your diagonal parameter in this latter case:

1/((-2 I + e) (1 + E^(
   1.5625\[CenterDot]10^22 (-(1/100000000000000000000) + e))) (2 I + 
   Conjugate[e]))

Ok, one sees that your integration variable was assumed complex along in your computation. Also see the huge numbers involved as well.

let's "fix" that and see what we get:

diagonal /. Conjugate[e] -> e

gives

$\frac{1}{(e-2 i) (e+2 i) \left(e^{1.5625\times 10^{22} \left(e-\frac{1}{100000000000000000000}\right)}+1\right)}$

and

Integrate[diagonal /. Conjugate[e] -> e, {e, 0, Infinity}]

returns unevaluated, not surprisingly given that something like

Integrate[x^x, x]

returns unevaluated. So, the upshot of this is to perhaps take a line by line look at your algorithm to see what is happening at each stage and then see if there are things that can be done to make sure that it is doing what you are wanting. If your final result is expected to be a numerical result then once your code is revised you will probably want to explore NIntegrate

POSTED BY: David Reiss
Posted 10 years ago

yes my final result is numerical.NIntegrate is very fast but it`s answer is zero! it is not correct. where can i use NIntegrate?

POSTED BY: esi fn
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract