# Calling ode function inside a user-defined function

**URL:** <https://scilab.discourse.group/t/calling-ode-function-inside-a-user-defined-function/1047>\
**Category:** General usage\
**Created:** [September 25, 2025, 3:22pm UTC](https://scilab.discourse.group/t/calling-ode-function-inside-a-user-defined-function/1047 "2025-09-25T15:22:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel.Enibe2](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Samuel.Enibe2](https://scilab.discourse.group/u/Samuel.Enibe2)\
**Post date:** [September 25, 2025, 3:22pm UTC](https://scilab.discourse.group/t/calling-ode-function-inside-a-user-defined-function/1047/1 "2025-09-25T15:22:19Z")

</div>

I have the need to call the SCILAB native ode function inside a user-defined function. But I find that this generates an error message.

For example, in the first example obtained by typing _help ode_, the script fails to execute if the ode function is called inside a user-defined function. Is there any solution to this problem

```auto
function ydot=f(t, y)
    ydot=y^2-y*sin(t)+cos(t)
endfunction
y0=0;
t0=0;
t=0:0.1:%pi;

y = ode(y0, t0, t, f);
plot(t,y)

//This does not work if ode is called inside a user-defined function
function [yy]=myexample(y0, t01, t)
y = ode(y0, t0, t, f);
plot(t,y)
endfunction

[yy] = myexample(y0.t0, t);//this call list the error "Attempt to reference field of non-structure array".

```

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [September 25, 2025, 3:27pm UTC](https://scilab.discourse.group/t/calling-ode-function-inside-a-user-defined-function/1047/2 "2025-09-25T15:27:26Z")

</div>

> [@Samuel.Enibe2](#):
>
> `[yy] = myexample(y0.t0, t);`

write it `[yy] = myexample(y0,t0, t)` (you used a dot instead of a comma).

S.

---

<div class="post-metadata">

**Author:** ![Samuel.Enibe2](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Samuel.Enibe2](https://scilab.discourse.group/u/Samuel.Enibe2)\
**Post date:** [September 25, 2025, 7:50pm UTC](https://scilab.discourse.group/t/calling-ode-function-inside-a-user-defined-function/1047/3 "2025-09-25T19:50:54Z")

</div>

Thank you very much for identifying the errors. I have corrected them and it is working perfectly.

Samuel Enibe  
University of Nigeria Nsukka
