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

2 views (last 30 days)
T K on 7 Dec 2022
Commented: T K on 10 Dec 2022
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')
Walter Roberson on 7 Dec 2022

Walter Roberson on 7 Dec 2022
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)
T K on 10 Dec 2022
Thanks alot@Walter Roberson