I have a pair of function and ode driver files. Currently, all values except initial conditions are declared as variables in the function file.
I would like to iterate on one variable, and check if the result is better than the previous value.
For example,
- start with Snh_in_1=1,
- run the ODE,
- print y(end,3).
- +0.1 to Ssnh (i.e. Snh_in_1 = 1.1)
- run the ODE,
- print new y(end,3).
- if new y(end,3), > original y(end, 3), repeat from step 1.
- stop when new y(end,3) less than or equal to previous y(end,3), and report this value of Snh_in_1.
These are my code so far
Function file: https://pastebin.com/Mp43ea1v
Driver file: https://pastebin.com/ct8iNL8W
I can imagine an if loop that might work:
result2 = 2;result1 = 1;Ssnh_in_1 = 1;if result2 >= result1 [t,y]=ode15s(@pha_cont,[0,15],y0); result1 = y(end,3); Ssnh_in_1 = Ssnh_in_1 + 0.1; [t,y]=ode15s(@pha_cont,[0,15],y0); result2 = y(end,3);else disp(Ssnh_in_1)end
But I have no idea how to pass this variable from the driver into the function file.
How can I do what I want in Matlab? Thanks in advance!
Best Answer