# Plotting 3D graph with ODEs

56 views (last 30 days)
Clement Koh on 21 Aug 2020
Commented: Clement Koh on 21 Aug 2020
Hello there, I am looking for a possible way to plot 3D surface/graphs/plot from the data set I get from a system of ODEs that I created and solved using ode45, but I am unsure of how to get it.
Lets say I have the function files of the system of ODEs,and each time I run, I manipulate the parameters one by one to see their effect on the ans I get. For eg, I started off with the parameter A=0, and B = 3, which allows me to get population(t). Then I changed one of the parameter each time, A = 0, 20, 40, 60, 80 100 respectively. For each value of A, I also changed the B= 3, 6, 9, 12. respectively. Isit possible for me to plot a combined 3D plot of A, B and the population(t) and is there a better way/less tedious way to program this? If so, what is the suggested steps that I should take or do?

J. Alex Lee on 21 Aug 2020
If your ODE result "population(t)" a scalar value, then yes, you can use surf() if your [A,B] is defined using meshgrid.

Clement Koh on 21 Aug 2020
Thanks!
In general, I would want to find out whats the population at every point of time when the value of A and B changes. Not sure how I could change my code below
Currently this is my code:
%Main
to = 0;
tf = 365;
tspan = to:1:tf;
y0 = [1000000 100];
[t1,Y1] = ode45(@Sub_3D_plot_1, tspan, y0);
A=[0 20 40 60 80 100];
B=[3 6 9 12];
z = ;%Trying to form this with results from dYdt(2) in the function file whenever A and B changes
[X,Y] = meshgrid(A,B);
surf(X,Y,z)
Here is my part of my function file:
function dYdt = Sub_3D_plot_1(t,Y)
for A =0:20:100
for B= 90:90:360
b = 1/B;
C = 10;
dYdt(1) = -(C*Y(1))+(b*(1+3));
dYdt(2) = (C*Y(1))-(0.02*Y(2));
end
end
end
J. Alex Lee on 21 Aug 2020
In a 3D plot, you have available 3 coordinates, x,y,z. You are using up (x,y) with your A and B values. You can represent a "point" at that (x,y) with another single value z. How do you expect a plot to look if you want multiple values of z stacked onto each other at that single (x,y)? Even if you did do that, how would you interpret the interrelation among those multiple stacked points (their relation in time, e.g.)?
Clement Koh on 21 Aug 2020
Alright, thanks for the input!