MATLAB Answers

How to make a contour plot with data from using ode45

6 views (last 30 days)
Binette Wadda
Binette Wadda on 1 Aug 2020
Commented: KSSV on 1 Aug 2020
So for my code im trying to vary two parameters used in a system of differential equations and evaluate how those different values affect a subset of the solution. I want to do this by creating a contour plot, but I cant seem to get my data to ailgn correctly.
X= linspace(1,5,5); % Vector for alpha_p values
Y= linspace(0.5,3,5); % Vector for beta_p values
[A, B]= meshgrid(X,Y);
for i= 1:length(A)
for j=length(B)
[t,x] = ode45(@(t,x) pulsegenerator_function2(t, x, 1, 5, 0.75, A(i,j), B(i,j), 5,...
0.75, A(i,j), B(i,j), 1, 2, 0.75, A(i,j), B(i,j), 3, 1, 2, 1 ), linspace(0,10,75), [0.1 0 0 0 0 0]);
so this is what I have right now, essentially I have a bunch of paramenters (as you can see after t and x in the function) and I'm trying to vary 2 of them at all possible combnations with each other and i dont know how to successfully do that.
After this issue I still dont understand how I can get the right size data to work for making a contour plot, but it might have to do with this first part so thats the most pressing issue at the moment

  2 Comments

Binette Wadda
Binette Wadda on 1 Aug 2020
so I want my Z axis to be pulse height, which is a measure of my max x values subtracted by steady state
SS(1,i)= x(75,1);
SS(2,i)= x(75,2);
SS(3,i)= x(75,3);
SS(4,i)= x(75,4);
SS(5,i)= x(75,5);
SS(6,i)= x(75,6);
YmRNA(:,i)= x(:,1);
Yprotein(:,i)= x(:,2);
XmRNA(:,i)= x(:,3);
Xprotein(:,i)= x(:,4);
ZmRNA(:,i)= x(:,5);
Zprotein(:,i)= x(:,6);
end
end
% Seperate steady state values for each protein at mRNA and Protein level
YmRNA_ss= SS(1,:);
YProtein_ss=SS(2,:);
XmRNA_ss= SS(3,:);
XProtein_ss=SS(4,:);
ZmRNA_ss= SS(5,:);
ZProtein_ss=SS(6,:);
Z= SS;
x1=XmRNA(:,1);
x2=XmRNA(:,2);
x3=XmRNA(:,3);
x4=XmRNA(:,4);
x5=XmRNA(:,5);
XmRNAmax= [nanmax(x1), nanmax(x2), nanmax(x3), nanmax(x4), nanmax(x5)];
p1=Xprotein(:,1);
p2=Xprotein(:,2);
p3=Xprotein(:,3);
p4=Xprotein(:,4);
p5=Xprotein(:,5);
Xproteinmax= [nanmax(p1), nanmax(p2), nanmax(p3), nanmax(p4), nanmax(p5)];
y1=YmRNA(:,1);
y2=YmRNA(:,2);
y3=YmRNA(:,3);
y4=YmRNA(:,4);
y5=YmRNA(:,5);
YmRNAmax= [nanmax(y1), nanmax(y2), nanmax(y3), nanmax(y4), nanmax(y5)];
y_p1=Yprotein(:,1);
y_p2=Yprotein(:,2);
y_p3=Yprotein(:,3);
y_p4=Yprotein(:,4);
y_p5=Yprotein(:,5);
Yproteinmax= [nanmax(y_p1), nanmax(y_p2), nanmax(y_p3), nanmax(y_p4), nanmax(y_p5)];
z1=ZmRNA(:,1);
z2=ZmRNA(:,2);
z3=ZmRNA(:,3);
z4=ZmRNA(:,4);
z5=ZmRNA(:,5);
ZmRNAmax= [nanmax(z1), nanmax(z2), nanmax(z3), nanmax(z4), nanmax(z5)];
z_p1=Zprotein(:,1);
z_p2=Zprotein(:,2);
z_p3=Zprotein(:,3);
z_p4=Zprotein(:,4);
z_p5=Zprotein(:,5);
Zproteinmax= [nanmax(z_p1), nanmax(z_p2), nanmax(z_p3), nanmax(z_p4), nanmax(z_p5)];
maxval= [XmRNAmax; Xproteinmax; YmRNAmax; Yproteinmax; ZmRNAmax; Zproteinmax];
Z=maxval-SS
This is the rest of my code, it looks like a lot but most of it is just clunky coding. essentially after i solve for x from ode45 i find the steady state value (which would be the last value of x at each itereation) and then find max values at each iteration, and subtratct to get my pulse height value.
Is it even possible to use this data in a contour plot? Or am i just going about it the wrong way

Sign in to comment.

Accepted Answer

KSSV
KSSV on 1 Aug 2020
X= linspace(1,5,5); % Vector for alpha_p values
Y= linspace(0.5,3,5); % Vector for beta_p values
[A, B]= meshgrid(X,Y);
nt = length(x) ; [m,n] = size(A) ;
Z = zeros(m,n,nt) ;
for i= 1:length(A)
for j=length(B)
[t,x] = ode45(@(t,x) pulsegenerator_function2(t, x, 1, 5, 0.75, A(i,j), B(i,j), 5,...
0.75, A(i,j), B(i,j), 1, 2, 0.75, A(i,j), B(i,j), 3, 1, 2, 1 ), linspace(0,10,75), [0.1 0 0 0 0 0]);
Z(i,j,:) = x ;
end
end
for i = 1:nt
contour(A,B,Z(:,:,i)
title(sprintf("contour at time step = %d",i))
drawnow
pause(1)
end

  2 Comments

Binette Wadda
Binette Wadda on 1 Aug 2020
Thank you for responding! I tried this but now the issue is that Z(i,j,:) and x are different dimensions. x is 75 by 5 while z is 3 dimensional, so they cannot be assigned to each other. I'm thinking maybe its how the parameters are iterated through? I'm not really sure
KSSV
KSSV on 1 Aug 2020
You save only a single column of x into Z for which you want a contour plot.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!