How to plot a 2D graph from a surface?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have the next code wich is an explicit finite difference scheme. I need to plot a (x,y) with respect from the time, what I need is a graphic for the evolution of "u" and "v" with respect from time.
Here is the code:
% Modelo de Sel'kov 2D utilizando un esquema FTCS de diferencias finitas
function []=RDzeroux(~,~,~)
clear all
close all
% Llenado del mallado
N = 100;
h = 1/N; % Tamaño de paso de x y y
x = h.*(0:N); % Coordenadas del mallado en x
y = h.*(0:N); % Coordenadas del mallado en y
[xx,~] = meshgrid(x,y); % Coordenadas x e y en 2D
dt = 10.*h;%0.8.*h.^2; % tamaño de paso temporal (usualmente pequeño)
% Valores de los parámetros
a = 0; %0; %0.08;
b = 0.9502; %0.6; %0.9502;
Du = 0.0002;
Dv = 0.0001;
% Initial data at t=0:
% us = (a+b); % u steady state
% vs = b/us^2; % v steady state
% u = (a+b)*ones(size(xx)); % u steady state
% v = (b./u.^2); % v steady state
u = b.*ones(size(xx)) + 0.01.*randn(size(xx)); % Pequeñas perturbaciones cercas del estado estable
v = b./(a+b).^2.*ones(size(xx)) + 0.01.*randn(size(xx));
t = 0;
tmax = 1;
fig = figure('position',[100 100 850 600]);
nsteps = round(tmax/dt); % número de pasos
vidObj = VideoWriter('Selkov2Datro.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
for n = 1:nsteps
t = t+dt;
uE = u(:,[2:N+1 N]);
uW = u(:,[2 1:N]);
uN = u([2 1:N],:);
uS = u([2:N+1 N],:);
vE = v(:,[2:N+1 N]);
vW = v(:,[2 1:N]);
vN = v([2 1:N],:);
vS = v([2:N+1 N],:);
% Squema FTSC
u2v = u.^2.*v;
u = u + dt*(a.*v - u + u2v) + Du*dt*(uE+uW+uN+uS-4*u)/h^2;
v = v + dt*(b - a.*v- u2v) + Dv*dt*(vE+vW+vN+vS-4*v)/h^2;
subplot(1,2,1)
p = pcolor(x, y, u);
title(['t=', num2str( t ), ' ATP(u)']);
colorbar;
set(p, 'EdgeColor', 'none', 'FaceColor', 'interp');
subplot(1,2,2)
p = pcolor(x, y, v);
title(['t=', num2str( t ), ' ADP(v)']);
colorbar;
set(p, 'EdgeColor', 'none', 'FaceColor', 'interp');
% plot(x,u,'g.-', 'linewidth',1);
% hold on;
% plot(x,v,'r.-', 'linewidth',1);
% hold off;
% legend('ATP','ADP')
% axis([0 1 0 2])
% title(['t = ', num2str(t)],'fontsize',24)
% drawnow;
% tmax
% t
writeVideo(vidObj, getframe(fig));%gca));
end
close(gcf)
close(vidObj);
winopen('Selkov2Datro.avi')
% Graficas solución
figure(1);
s = surf(x,y,u);
set(s, 'EdgeColor', 'none', 'FaceColor', 'interp');
title(['u en t = ' num2str(t)],'fontsize',16)
xlabel('<----x---->')
ylabel('<----y---->')
zlabel('<----t---->')
figure(2)
s = surf(x,y,v);
set(s, 'EdgeColor', 'none', 'FaceColor', 'interp');
title(['v en t = ' num2str(t)],'fontsize',16)
xlabel('<----x---->')
ylabel('<----y---->')
zlabel('<----t---->')
figure(3);
p = pcolor(x, y, u);
colorbar;
set(p, 'EdgeColor', 'none', 'FaceColor', 'interp');
figure(4);
q = pcolor(x, y, v);
colorbar;
set(q, 'EdgeColor', 'none', 'FaceColor', 'interp');
Please, help me to do that, what I need is something like this:

where the red line is "u" and the green line is "v".
Please help me add something in my code.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!