필터 지우기
필터 지우기

How to create a better 3D Discrete Plot?

조회 수: 2 (최근 30일)
Athanasios Paraskevopoulos
Athanasios Paraskevopoulos 2024년 3월 10일
댓글: Voss 2024년 3월 10일
I am study the Discrete Klein-Gordon Equation.
By interpreting the equation in this way, we can relate the dynamics described by the discrete Klein - Gordon equation to the behavior of DNA molecules within a biological system . This analogy allows us to understand the behavior of DNA in terms of concepts from physics and mathematical modeling . Is ti possivle to I create a nicer 3D plot than the following?
% Parameters
numBases = 100; % Number of base pairs
kappa = 0.1; % Elasticity constant
omegaD = 0.2; % Frequency term
beta = 0.05; % Nonlinearity coefficient
% Initial conditions
initialPositions = 0.01 + (0.02 - 0.01) * rand(numBases, 1);
initialVelocities = zeros(numBases, 1);
% Time span for the simulation
tSpan = [0 50];
% Differential equations function
odeFunc = @(t, y) [y(numBases+1:end); ... % velocities
kappa * ([y(2); y(3:numBases); 0] - 2 * y(1:numBases) + [0; y(1:numBases-1)]) + ...
omegaD^2 * (y(1:numBases) - beta * y(1:numBases).^3)]; % accelerations
% Solve the system numerically
[T, Y] = ode45(odeFunc, tSpan, [initialPositions; initialVelocities]);
% Specific time points for visualization
timePoints = [0, 10, 20, 30, 40, 50];
% Initialize the figure for 3D plot
figure;
hold on;
% Plotting the dynamics in 3D
for i = 1:length(timePoints)
time = timePoints(i);
[~, timeIndex] = min(abs(T - time)); % Find the index of the closest time in T
displacements = Y(timeIndex, 1:numBases); % Displacement values at this time point
% Plotting each base pair displacement as a line in 3D space
plot3(1:numBases, repmat(time, 1, numBases), displacements, 'LineWidth', 2);
end
hold off;
xlabel('Base Pair');
ylabel('Time');
zlabel('Displacement');
title('3D Plot of DNA Base Pair Displacements Over Time');
view(3); % Adjust the view to see the plot in 3D

채택된 답변

Voss
Voss 2024년 3월 10일
Maybe a surface? Something like this:
% Parameters
numBases = 100; % Number of base pairs
kappa = 0.1; % Elasticity constant
omegaD = 0.2; % Frequency term
beta = 0.05; % Nonlinearity coefficient
% Initial conditions
initialPositions = 0.01 + (0.02 - 0.01) * rand(numBases, 1);
initialVelocities = zeros(numBases, 1);
% Time span for the simulation
tSpan = [0 50];
% Differential equations function
odeFunc = @(t, y) [y(numBases+1:end); ... % velocities
kappa * ([y(2); y(3:numBases); 0] - 2 * y(1:numBases) + [0; y(1:numBases-1)]) + ...
omegaD^2 * (y(1:numBases) - beta * y(1:numBases).^3)]; % accelerations
% Solve the system numerically
[T, Y] = ode45(odeFunc, tSpan, [initialPositions; initialVelocities]);
% Specific time points for visualization
timePoints = [0, 10, 20, 30, 40, 50];
% Initialize the figure for 3D plot
figure;
% Plotting the dynamics in 3D
[~, timeIndex] = min(abs(T - timePoints),[],1); % Find the index of the closest time in T
surf(1:numBases, repmat(timePoints(:), 1, numBases), Y(timeIndex, 1:numBases), ...
'EdgeColor', 'none', 'FaceColor', 'interp')
box on;
xlabel('Base Pair');
ylabel('Time');
zlabel('Displacement');
title('3D Plot of DNA Base Pair Displacements Over Time');
view(3); % Adjust the view to see the plot in 3D
  댓글 수: 4
Athanasios Paraskevopoulos
Athanasios Paraskevopoulos 2024년 3월 10일
Thank you very much for your help and your time!!!
Voss
Voss 2024년 3월 10일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by