# How to use parameter function instead of parameter values?

**URL:** <https://pybamm.discourse.group/t/how-to-use-parameter-function-instead-of-parameter-values/106>\
**Category:** PyBaMM Q&A\
**Created:** [19 January 2025 12:03 UTC](https://pybamm.discourse.group/t/how-to-use-parameter-function-instead-of-parameter-values/106 "2025-01-19T12:03:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gulzar223](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gulzar223](https://pybamm.discourse.group/u/gulzar223)\
**Post date:** [19 January 2025 12:03 UTC](https://pybamm.discourse.group/t/how-to-use-parameter-function-instead-of-parameter-values/106/1 "2025-01-19T12:03:47Z")

</div>

Hi everyone,  
I’m working on a project using PyBaMM, and trying to update parameter values by uploading a custom parameter function. However, I’m unsure about the correct way to do this.  
Could someone guide me on how to define and upload parameter functions in PyBaMM to replace or modify default parameter values? Any examples or tips you can give me would be greatly appreciated!  
I really appreciate any help you can provide.

---

<div class="post-metadata">

**Author:** ![amundmr](https://yyz2.discourse-cdn.com/free1/user_avatar/pybamm.discourse.group/amundmr/32/30_2.png) [@amundmr](https://pybamm.discourse.group/u/amundmr)\
**Post date:** [20 January 2025 12:11 UTC](https://pybamm.discourse.group/t/how-to-use-parameter-function-instead-of-parameter-values/106/2 "2025-01-20T12:11:29Z")

</div>

Hi,

You just define your function, e.g.:

```auto
def custom_ocp(sto):
    x = sto
    p = np.array([1.20912055e+00, 5.62297420e+01, -1.11020020e-01, -2.53458213e-01, 4.92581391e+01, 1.22046522e-02, 4.73538620e-02, 1.79631246e+01, 1.75283209e-01, 1.88038929e-02, 3.03255334e+01, 4.66328034e-01])
    
    return (
            p[0] * pb.exp(-p[1] * x)
            + p[2]
            - p[3] * pb.tanh(p[4] * (x - p[5]))
            - p[6] * pb.tanh(p[7] * (x - p[8]))
            - p[9] * pb.tanh(p[10] * (x - p[11]))
        )

```

And then you insert it into the parameter set, e.g:

```auto
param = pb.ParameterValues("Chen2020")
param.update({'Positive electrode OCP [V]': custom_ocp}, check_already_exists=False)

```

Also, see the official [documentation](https://docs.pybamm.org/en/stable/source/examples/notebooks/getting_started/tutorial-4-setting-parameter-values.html), and make sure that the parameter you are trying to set to a function is actually described as a `FunctionParameter`.

good luck 🙂
