简体   繁体   English

使用Runge Kutta方法打印两个值

[英]Printing two values using Runge Kutta Method

I am trying to print b and c from this code, but I am not having any luck. 我正在尝试从此代码中打印b和c,但是我没有任何运气。 If I am correct, this code should output several points with a step size of 0.05, but I am not seeing it. 如果我是正确的,则此代码应输出步长为0.05的几个点,但是我看不到它。 Does anyone know how to print two values from this code? 有谁知道如何从此代码中打印两个值?

import math

def rK3(a, b, c, fa, fb, fc, hs):
    a1 = fa(a, b, c)*hs
    b1 = fb(a, b, c)*hs
    c1 = fc(a, b, c)*hs
    ak = a + a1*0.5
    bk = b + b1*0.5
    ck = c + c1*0.5
    a2 = fa(ak, bk, ck)*hs
    b2 = fb(ak, bk, ck)*hs
    c2 = fc(ak, bk, ck)*hs
    ak = a + a2*0.5
    bk = b + b2*0.5
    ck = c + c2*0.5
    a3 = fa(ak, bk, ck)*hs
    b3 = fb(ak, bk, ck)*hs
    c3 = fc(ak, bk, ck)*hs
    ak = a + a3
    bk = b + b3
    ck = c + c3
    a4 = fa(ak, bk, ck)*hs
    b4 = fb(ak, bk, ck)*hs
    c4 = fc(ak, bk, ck)*hs
    a = a + (a1 + 2*(a2 + a3) + a4)/6
    b = b + (b1 + 2*(b2 + b3) + b4)/6
    c = c + (c1 + 2*(c2 + c3) + c4)/6
    return a, b, c

def fa2(a, b, c):
    return 0.9*(1 - b*b)*a - b + math.sin(c)

def fb2(a, b, c):
    return a

def fc2(a, b, c):
    return 0.5

def VDP2():
    a, b, c, hs = 1, 1, 0, 0.05
    while (c<6):
        a, b, c = rK3(a, b, c, fa2, fb2, fc2, hs)

Your code does not have any print statement, so it will not print. 您的代码没有任何打印语句,因此将不会打印。 Try inserting something like: 尝试插入如下内容:

print 'b = {0}, c = {1}'.format(b,c)

Where you want the print to happen. 您希望进行打印的位置。 For Python 3 just add parentheses (print is a function now) 对于Python 3,只需添加括号即可(print现在是一个函数)

print('b = {0}, c = {1}'.format(b,c))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM