Python Forum
Defining an fsolve function to call later
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining an fsolve function to call later
#1
def myFunction_2(p,skewness,kurtosis):
      x=p[0]
      y=p[1]
      z=p[2]
      f=empty((3))
      f[0]=pow(x,2)+pow(y,2)+6*x*y+15*pow(z,2)-1
      f[1]=8*pow(y,3)+ 6 * pow(x,2) * y + 72 * x * y * z + 270 * y * pow(z,2) - skewness
      f[2]=3 * x**4 + 60 * x**2 * y**2 + 60 * y**4 + 60 * x**3 * z +936 * x * y**2 *z + 630 * x**2 * z**2 + 4500 * y**2 * z**2 + 3780 * x * z**3 + 10395 * z**4-3-kurtosis
     return f
zGuess=array([2,2,2])
z=fsolve(myFunction_2,zGuess)
I am trying to define a function wherein skewness and kurtosis arguments can vary and I want thus the solution to the non linear equations. However, I get an error message that reads "myFunction_2() takes exactly 3 arguments (1 given)". I have specified these arguements in the equations f[1] and f[2], to be able to call the function later with varying values of kurtosis and skewness- What am I doing wrong?
Reply
#2
I figured out my mistake,

I am supposed to call skewness and kurtosis in a tuple. In effect, the program must be programed as follows:

def myFunction_2(p,args=(skewness,kurtosis)):
      x=p[0]
      y=p[1]
      z=p[2]
      f=empty((3))
      f[0]=pow(x,2)+pow(y,2)+6*x*y+15*pow(z,2)-1
      f[1]=8*pow(y,3)+ 6 * pow(x,2) * y + 72 * x * y * z + 270 * y * pow(z,2) - skewness
      f[2]=3 * x**4 + 60 * x**2 * y**2 + 60 * y**4 + 60 * x**3 * z +936 * x * y**2 *z + 630 * x**2 * z**2 + 4500 * y**2 * z**2 + 3780 * x * z**3 + 10395 * z**4-3-kurtosis
     return f
zGuess=array([2,2,2])
z=fsolve(myFunction_2,zGuess)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 801 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how can I solve fsolve function error? troddydeeneeeeeey 3 2,450 Oct-14-2021, 07:07 PM
Last Post: deanhystad
  Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} ) DimosG 2 2,837 Sep-21-2021, 08:32 PM
Last Post: 1968Edwards
  how to call an object in another function in Maya bstout 0 2,089 Apr-05-2021, 07:12 PM
Last Post: bstout
  Defining a function with input abcd 5 3,132 Feb-21-2021, 02:34 AM
Last Post: NullAdmin
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,508 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,233 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,922 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,254 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,091 Jul-27-2020, 04:19 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020