0

I am having a function to solve by ode45. To make it easy, I will use this mock-up case to present my question:

The actual differential function is y' = f(time, y, current), while current is a function of time, that has a value at every time point. For example, time = [0.001, 0.002, 0.003] and current = [0.123, 0.456, 0.789]. However, when I use ode45, I have to write the function in the following format:

function dy = odefun(t, y)
dy = some code % some code calculates y' = f(time, y, current)
end

And therefore, I am stuck in how to pass in the parameter "current". It would be much easier if current is a constant, but it's not.

One workaround is to write a function getCurrent(time); however, that means I need to search the time vector, find a match and its index, and then return current. The searching process may take quite a long time to finish.

So, I was wondering, is there a more correct way to do it?

Thanks!

4

0 回答 0