I want to plot height[time] function for different values of M and g. This function contains a[2] which needs to be found. I had two-coupled algebraic equation for a[2] and t[2]. I used Solve to solve that system and it worked. However the issue starts at that point, when I execute below code, it does not produce a graph. I did something wrong, but the question is "where". Please see below;

p01[x_] := Integrate[2*a[2]/k*1/(x - c) + t[2]/k , {x, 0, x},Assumptions -> 0 < x < c] + 1/2

p02[x_] := Integrate[2*a[2]/k*1/(x - c) + t[2]/k , {x, 1, x},Assumptions -> c < x < 1] 

first[x_] := Integrate[p01[x], {x, 0, c}, Assumptions -> 0 < c < 1]

second[x_] := Integrate[p02[x], {x, c, 1}, Assumptions -> 0 < c < 1]

third[x_] := Integrate[(x - c)*p01[x], {x, 0, c}, Assumptions -> 0 < c < 1]

fourth[x_] := Integrate[(x - c)*p02[x], {x, c, 1}, Assumptions -> 0 < c < 1]

Solve[2*M*a[2] == first[x]+second[x] - M*g && 2*M*i*t[2] ==third[x]+fourth[x], {a[2], t[2]}]

c = 0.4; k = 1; i = 0.2;

a[0] = k*c*(1 - c);
t[0] = k*(1 - 2*c);

height[time_] := a[0] + time^2*a[2]

plot4 = Block[{M = {0, 0.1, 1, 10}, g = {0, 0.1, 1, 10}}, 
  Plot[Evaluate@height[time], {time, 0, 1}, AxesOrigin -> {0, 0}, 
   PlotStyle -> {Red, Green, Blue, Black}]]
  • 1
    $\begingroup$ These is no question in this post. If there's a problem with your code and you want it solved, please state it clearly, and construct a complete but minimal example. Post no more code than what is needed to reproduce the problem. That will certainly be less than what's here. See sscce.org for guidance. $\endgroup$
    – Szabolcs
    Oct 15, 2016 at 16:07
  • $\begingroup$ Thanks @Szabolcs, I have edited the post. The issue is plotting in this above code. It does not give me a graph. Might be because of the definition of parameters. I cannot figure it out! $\endgroup$
    – Meva
    Oct 15, 2016 at 16:25
  • $\begingroup$ it seem, that $b$ in third[] and fourth[] is not defined. furthermore: in the definition of heigth[] a[2] has to be replaced by the solution a[2] from Solve[]: (sol = Solve[ 2*Ma[2] == first[x] + second[x] - Mg && 2*Mit[2] == third[x] + fourth[x], {a[2], t[2]}] and height[time_] := a[0] + time^2*a[2] /. sol[[1, 1]]) $\endgroup$
    – Armin
    Oct 15, 2016 at 16:30
  • $\begingroup$ @Armin, thanks to your comment, I changed b to c. It was a typo. Anyway it still does not work. Also a big thank you for the second part of your comment about dividing sol[[1,1]] . So is sol[[2,1]] for t[2] then?? $\endgroup$
    – Meva
    Oct 15, 2016 at 16:35

1 Answer 1


Look, there are several issues with your code which is why it is important that you tear the pieces apart before posting a question. I'm sure you could have solved this yourself.

  1. You don't use the solution for a[2] and t[2]. You call Solve correctly, but you don't store the solution and use it in Plot.
  2. You have a mystical b in your code-block that never gets a value.

Want to know how you easily find all this issues? One easy way is always to not use Plot because then you only see an empty graph. What I usually do is to type Plott which is a function that is not defined and therefore, nothing happens except that you really see the parameters. So after evaluating your code-block do (see the Plott!):

Mathematica graphics

Now you see that there is an unevaluated a[2] in there. So the first thing you do is to store the solution of Solve

sol = 
   2*M*a[2] == first[x] + second[x] - M*g && 
    2*M*i*t[2] == third[x] + fourth[x], {a[2], t[2]}]

and use it

Mathematica graphics

Now, you see that your formula contains the b which needs a value. I'll set it to b=1 in the Block and replace Plott with Plot again and there you have it

Mathematica graphics

  • $\begingroup$ this is great answer, thanks so much. As you posted I did sol = Flatten@Solve[ 2*Ma[2] == first[x] + second[x] - Mg && 2*Mit[2] == third[x] + fourth[x], {a[2], t[2]}] but a[2] is still not recognised. Then I used height[time_] := a[0] + time^2*a[2] /. sol[[1, 1]] but the outcome for height[time] is 0.24+t^2a[2] a[2]. I started kernel then evaluated again all, but it did not revealed. $\endgroup$
    – Meva
    Oct 15, 2016 at 16:53
  • $\begingroup$ Here is the exact code that I used: Import["http://goo.gl/NaH6rM"]["http://i.stack.imgur.com/ZrHmp.png"] Please copy and evaluate the complete import statement. $\endgroup$
    – halirutan
    Oct 15, 2016 at 16:57
  • $\begingroup$ I am so thankful @halirutan, but I guess the content of those links are not so relevant e.g it says the png file is no longer available, so I cannot see what is inside. But again, thanks.. $\endgroup$
    – Meva
    Oct 15, 2016 at 17:17
  • $\begingroup$ That is very weird. It is the first time that imgur deleted an image. Please try this one Import["http://goo.gl/NaH6rM"]["http://i.stack.imgur.com/1DsxV.png"] At this moment the image is available. I don't know for how long.. $\endgroup$
    – halirutan
    Oct 15, 2016 at 17:20
  • $\begingroup$ Unfortunately not @halirutan. So, should I try this : height[time_] := a[0] + time^2*a[2] /. sol[[1, 1]] , but as I say, it still does not give a[2] . I understand Mathematica can't assign the results of a Solve to the unknowns because there may be more than 1 solution. $\endgroup$
    – Meva
    Oct 15, 2016 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.