Hey,(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):function dy = pizzaode(t, y)

a=2;

b=0.5;

d=4;

u=y(1);

v=y(2);

dy = nan(2,1);

dy(1) = u*(1-u) - a*u*v/(u+d);

dy(2) = b*v*(1-v/u);

endCode (Text):[t,y] = ode45(@pizzaode, [0 100], [u(1);v(1)]);This works but it's crap.

Why?

- Ugly code.Code (Text):a=2;

b=0.5;

d=4;

I want to set the params outside the function.

So ok, I did this:

Code (Text):function [t,y] = pizzamaker(a, b, d, u0, v0)

[t,y] = ode45(@pizzaode, [0 100], [u0;v0]);

function dy = pizzaode(t, y)

u=y(1);

v=y(2);

dy = nan(2,1);

dy(1) = u*(1-u) - a*u*v/(u+d);

dy(2) = b*v*(1-v/u);

end

end

And that's nice because it works. But how would I do this without this strange nesting?

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab ODE-Solver and Constant Params

Loading...

Similar Threads - Matlab Solver Constant | Date |
---|---|

A Numerical solution in matlab | Sep 26, 2016 |

I Crank-Nicholson in 2D with MATLAB | May 23, 2016 |

Dont know how to write PDE of semiconductors in Matlab (PDE solver) | Mar 24, 2012 |

Help!, solving simple PDE with ODE45 or ODE23 solver in matlab | Jan 22, 2010 |

Matlab solver question | Oct 25, 2009 |

**Physics Forums - The Fusion of Science and Community**