Filter löschen
Filter löschen

How to plot 3D plotting

1 Ansicht (letzte 30 Tage)
Dereje
Dereje am 31 Mai 2019
Kommentiert: Walter Roberson am 1 Jun. 2019
I need help on how to plot the following 2D plot in to a 3D plot.
zspan=[0,400];
v0mat = [1 0.01 1];
zsol = {};
v1sol = {};
v2sol = {};
v3sol = {};
for k=1:size(v0mat,1)
v0=v0mat(k,:);
[z,v]=ode45(@rhs,zspan,v0);
zsol{k}=z;
v1sol{k}=v(:,1);
v2sol{k}=v(:,2);
v3sol{k}=v(:,3);
end
for k=1:size(v0mat,1)
figure(1)
plot(v2sol{k},zsol{k},'g')
hold on
xlabel('Velocity,w')
ylabel('Height, z')
grid on
end
function parameters=rhs(z,v)
alpha=0.116;
db= 2*alpha-(v(1).*v(3))./(2*v(2).^2);
dw= (v(3)./v(2))-(2*alpha*v(2)./v(1));
dgmark= -(2*alpha*v(3)./v(1));
parameters=[db;dw;dgmark];
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Mai 2019
It wasn't clear what you wanted the z to be, so I guessed that it was the initial dw, which presumably later you will vary.
zspan = linspace(0,400,50);
v0mat = [1 0.01 1];
N = size(v0mat, 1);
zsol = cell(N,1);
v1sol = cell(N,1);
v2sol = cell(N,1);
v3sol = cell(N,1);
v2in = cell(N,1);
for k=1:size(v0mat,1)
v0 = v0mat(k,:);
[z,v] = ode45(@rhs,zspan,v0);
zsol{k} = z;
v1sol{k} = v(:,1);
v2sol{k} = v(:,2);
v3sol{k} = v(:,3);
v2in{k} = v0mat(2) * ones(size(v2sol{k}));
end
all_z = [zsol{:}];
all_v2 = [v2sol{:}];
all_v2in = [v2in{:}];
plot3(all_v2, all_z, all_v2in);
xlabel('Velocity,w')
ylabel('Height, z')
zlabel('initial dw')
  5 Kommentare
Dereje
Dereje am 1 Jun. 2019
But it returns an error which says, Z must be a matrix, not a scalar or vector.
Walter Roberson
Walter Roberson am 1 Jun. 2019
This is because you only have one row in v0mat so what should be 2D arrays are coming out as vectors.
Also, all of the interesting height (z_span) is between 0 and 2, and going up to 400 is losing all of the important information.
zspan = linspace(0,2,50);
v2in_vals = linspace(0.01,0.05,10);
v0mat = [1 0.01 1];
N = size(v0mat, 1);
zsol = cell(N,1);
v1sol = cell(N,1);
v2sol = cell(N,1);
v3sol = cell(N,1);
v2in = cell(N,1);
for k=1:length(v2in_vals)
v0 = v0mat;
v0(2) = v2in_vals(k);
[z,v] = ode45(@rhs,zspan,v0);
zsol{k} = z;
v1sol{k} = v(:,1);
v2sol{k} = v(:,2);
v3sol{k} = v(:,3);
v2in{k} = v0mat(2) * ones(size(v2sol{k}));
end
all_z = [zsol{:}];
all_v2 = [v2sol{:}];
all_v2in = [v2in{:}];
subplot(1,2,1);
plot3(all_v2, all_z, all_v2in);
xlabel('Velocity,w')
ylabel('Height, z')
zlabel('initial dw')
subplot(1,2,2)
v2in_vec = v2in_vals;
z_vec = all_v2(:,1);
surf(z_vec, v2in_vec, all_v2.')
xlabel('Height, z');
ylabel('initial dw');
zlabel('Velocity,w');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Programming 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!

Translated by