Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Could anyone help me with the attached code? How would you speed up my attached code in some degree? Your comments are highly welcome.

ClearAll["Global`*"];
α = 0.95; k = 1000; M = 25000;

t0 = 0; tf = 25; h = (tf - t0)/M;

g1[t_] := 0.55;

x1[i_ /; -k <= i <= 0] := g1[t];

t[j_] := j*h

alfa = 0.75;

f1[t_, u_, v_] := u - u*u*u - alfa*v

x1[j1_] := x1[j1] = 
   g1[0] + (h^α/Gamma[α + 2])*
     f1[t[j1], 
      g1[0] + (1/Gamma[α])*
        Sum[(h^α/α)*((j1 - 1 + 1 - j)^α - (j1 - 
               1 - j)^α)*
                     f1[t[j], x1[j], x1[j - k]], {j, 0, j1 - 1}], 
      x1[j1 - k]] + (h^α/Gamma[α + 2])*

     Sum[Which[
        j == 0, (j1 - 1)^(α + 1) - (j1 - 
            1 - α)*(j1 - 1 + 1)^α, 
        1 <= j <= j1 - 
      1, (j1 - 1 - j + 2)^(α + 1) + (j1 - 1 - 
        j)^(α + 1) - 
               2*(j1 - 1 - j + 1)^(α + 1), True, 1]*
   f1[t[j], x1[j], x1[j - k]], {j, 0, j1 - 1}]; 

ListLinePlot[Table[{t[n], x1[n]}, {n, 0, 25000}]]
share|improve this question
9  
There is no code attached... just an image. Please include your code as text and without fancy formatting (i.e. no superscript/subscript). –  rm -rf Dec 21 '13 at 19:45
3  
Vedat, I see that there is code in your profile(!) now. It doesn't appear to be the same code as in the image however. Is that something you want help with too? –  Mr.Wizard Dec 21 '13 at 20:22
2  
@rm-rf, well an image is a perfectly valid Mathematica expression... –  Simon Woods Dec 21 '13 at 22:36
1  
Vedat, select this code snippet from your Mathematica notebook, copy it, and paste it into your answer. Then select it with your mouse again, and turn it into a preformatted code block (click the curly braces on the toolbar above the edit window). An image is useless to answerers. But we can copy/paste that preformatted snippet to our own Mathematica notebooks and test it/ play with it. –  Jyrki Lahtonen Dec 22 '13 at 7:32
2  
Why would you define g1[t_] := 0.55; ? A function of t that is a constant? why not just write g1=0.55 ? And why call x1 like this: x1[i_ /; -k <= i <= 0] := g1[t]; Then call g[t] where did the t come in this context? I see no t at all here. The problem with the code is that it mixes global and local symbols from all over the place. Try to break the code to separate cells. Each cell does one thing before the second. Make sure each part of the code evaluates correctly before the next. Do not try to run 100 lines of code at once then wonder where is the problem. –  Nasser Dec 22 '13 at 9:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.