Hello,
I have a food web that is driven by differential equations, that includes changes in plants, animals, and boat ‘population’. There are variables such as amount of fish harvested (catch_F
) and fish price (fish_price
) which influence the population of harvested fish species and ‘population’ of boats, but are not saved at each time step of the solution (like the populations).
In the end I would like to be able to plot fish price vs harvested fish population, and harvested fish vs boat ‘population’. But I can’t figure it out. I assume I need to save the value of fish harvested and fish price at each time step.
dBdT = function(dB, bioS, p, t)
D, S, K, v, r, X, num_nutrient, num_plant, num_animal, num_vessel_types, bm, foodWeb, b, q, ω, c, h, e, target_species, catch_max, b0V, μ, elasticity, clearance_V_type = p
results = fill(NaN,2) # I need to pre-allocate an array for catch_F and fish_price
# rate of change in clearance rate
if target_species != 0 # if there is some harvest
clearance_V = create_clearance_V(clearance_max,bioS,β_V,b0V,clearance_min, target_species,clearance_V_type)
catch_F = (catch_max*bioS[target_species]/(catch_max/clearance_V+bioS[target_species]))*bioS[(num_nutrient+num_plant+num_animal+num_vessel_types)]
dB[num_nutrient+num_plant+num_animal+num_vessel_types+1] = 0.0
fish_price = (catch_F/γ_fish)^(1/elasticity)
revenue = fish_price*catch_F
cost_V = maintenance+clearance_cost_scale*clearance_V
cost_F = cost_V*bioS[(num_nutrient+num_plant+num_animal+num_vessel_types)]
results = [catch_F fish_price]
results2 = vcat(results)
else # in absence of harvest
dB[num_nutrient+num_plant+num_animal+num_vessel_types+1] = 0.0
catch_F = 0.0
end
... #rest of differential equations
return results2 # I need to make results exist outside of the function
end
But it says results2 not defined?
And then how to graph it? I assume it will be
plot(sol, vars = ((num_nutrient+num_plant+num_animal+num_vessel_types),results2[1,]), title = "Clearance 1 - Vessels vs Catch", xlabel = "Vessel Coverage (1/m²)" ,ylabel = "Harvested Fish (g)", lw=1, legend=false)