surface plotting.surface plot poroblem. Please I want help. An error appears when running

조회 수: 1 (최근 30일)
T K
T K 2022년 12월 7일
댓글: T K 2022년 12월 10일
Please I want help. An error appears when running #code
w = 1; k=1; figure tspan = linspace(0, 5); % Create Constant ‘tspan’ zv=0.1:0.01:0.5; % Vector Of ‘z’ Values gs2 = zeros(numel(tspan), numel(zv)); % Preallocate for k = 1:numel(zv) z = zv(k); f = @(t,x) [-1i.*(2*w + 2*z).*x(1) + -1i.*sqrt(2).*k.*x(2);-1i.*sqrt(2).*k.*x(1) + -1i.*2*w*x(2)+-1i.*sqrt(2).*k.*x(3);-1i.*sqrt(2).*k.*x(2)+-1i.*2*w*x(3)]; [t,xa] = ode45(f,tspan,[0 1 0]); gs = abs(xa).^2; gs2(:,k) = gs(:,2); % Save Second Column Of ‘gs’ In ‘gs2’ Matrix end
figure surf(t,zv,gs2') grid on xlabel('t') ylabel('z') shading('interp')

답변 (1개)

Walter Roberson
Walter Roberson 2022년 12월 7일
w = 1;
k=1;
figure
tspan = linspace(0, 5); %must be a vector of length 3 or more
zvals = 0.1:0.01:0.5;
numt = length(tspan);
numz = length(zvals);
gs = zeros(numt, 3, numz);
for zidx = 1 : numz
z = zvals(zidx);
f = @(t,x) [-1i.*(2*w + 2*z).*x(1) + -1i.*sqrt(2).*k.*x(2);-1i.*sqrt(2).*k.*x(1) + -1i.*2*w*x(2)+-1i.*sqrt(2).*k.*x(3);-1i.*sqrt(2).*k.*x(2)+-1i.*2*w*x(3)];
[t,xa] = ode45(f,tspan,[0 1 0]);
gs(:,:,zidx) = abs(xa).^2;
end
G = squeeze(gs(:,2,:)) .';
surf(t,zvals,G)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by