VBA: Derivative and Tangent on an Excel Chart

cipango Posted messages 26 Status Member -  
 cipango -
Hello everyone.
I am looking for a macro that allows a tangent line to appear in the form of a straight segment or a double arrow, for example, 2 cm long, at a point on a curve in an Excel graph. The macro could ask the user for the coordinates of the point. Or better, the macro could appear in the context menu by right-clicking on the point in question.
The slope (gradient) calculation could be done using the point that follows and the point that precedes the curve point at which we are drawing the tangent. Or better (!), using the Solver or a trendline (?), create new intermediate points (not necessarily visible to the user) between the points in the table, with a small step dx in the x-axis, to ultimately approximate a derivative. And optionally, or rather through a new macro, display in a column of the table the value of the derivative for each point in the table.
I’m not sure if I’m being clear... In any case, this kind of "option" exists in most spreadsheets used in physical sciences. So why not in Excel?
Thank you in advance for your suggestions.

5 answers

  1. cipango Posted messages 26 Status Member 6
     
    Good evening everyone,
    I've obviously managed to calculate a rate of variation in a column, which gives me a fairly good value for the slope of the tangent when the points are close enough, but I don't know how to plot these tangents on the curve.
    If anyone has an idea...
    Thank you.
    2
  2. mirza
     
    Hi Cinpago,

    the best in my opinion:
    you use a physics table, make the diagram + copy/paste (with alt + print screen then ctrl+v) into Excel.
    1
  3. cipango Posted messages 26 Status Member 6
     
    Of course Mirza...
    But I want to use Excel only, and not a spreadsheet for physics that is found on hardly any machine and that no one knows about.
    1
  4. blux Posted messages 5035 Registration date   Status Moderator Last intervention   3 455
     
    Well, you include those values when plotting the curve, so it will draw you a nice line (but without an arrow at the end), right?

    A+ Blux
     "Stupid people dare to do anything. That's how you recognize them." 
    0
  5. cipango
     
    I need to create a line (two wisely chosen points are enough) for EACH tangent drawn!!! This results in a considerable number, and I don't know where to put these points in the table, whether to keep them or not...
    I would also like the manipulation to be simple, for example a right-click on the point of the curve and clicking on "tangent" in the context menu. Or another quick and "invisible" procedure for the user.
    Feel free to suggest a code if you have an idea.
    Thank you.
    0