Drawing directions fields

后端 未结 3 1221
予麋鹿
予麋鹿 2021-02-04 06:23

Is there a way to draw direction fields in python?

My attempt is to modify http://www.compdigitec.com/labs/files/slopefields.py giving

#!/usr/bin/python
         


        
3条回答
  •  野性不改
    2021-02-04 06:48

    Try changing your values for the parameters to this:

    XSCL = .2
    YSCL = .2
    

    These parameters determine how many points are sampled on the axes.


    As per your comment, you'll need to also plot the functions for which the derivation dy_dx(x, y) applies.

    Currently, you're only calculating and plotting the slope lines as calculated by your function dy_dx(x,y). You'll need to find (in this case 3) functions to plot in addition to the slope.

    Start by defining a function:

    def f1_x(x):
        return x**3-x**2-2x;
    

    and then, in your loop, you'll have to also write the desired values for the functions into the fileobj file.

提交回复
热议问题