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
  Defining function error rclaxton 1 456 Mar-27-2025, 11:42 AM
Last Post: buran
  not able to call the variable inside the if/elif function mareeswaran 3 502 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  Defining a function Hudjefa 6 1,050 Aug-24-2024, 02:36 PM
Last Post: snippsat
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 1,846 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how can I solve fsolve function error? troddydeeneeeeeey 3 3,836 Oct-14-2021, 07:07 PM
Last Post: deanhystad
  Conjugate Gradient having issues with defining A (function to solve [A]{x} = {b} ) DimosG 2 3,475 Sep-21-2021, 08:32 PM
Last Post: 1968Edwards
  how to call an object in another function in Maya bstout 0 2,621 Apr-05-2021, 07:12 PM
Last Post: bstout
  Defining a function with input abcd 5 4,179 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 4,870 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 3,016 Oct-29-2020, 02:45 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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