surface plotting.surface plot poroblem. Please I want help. An error appears when running
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 7 Dez. 2022
You changed your code after I answered your question :(
Please format the code.
Antworten (1)
Walter Roberson
am 7 Dez. 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)
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!