Hi guys, my code doesn't run i couldn't debug this, could you anyone help me?
1 回表示 (過去 30 日間)
古いコメントを表示
% Constants and parameters
alpha = 2; % Shear wave velocity
beta = 1; % Compressional wave velocity
frequencies = 0:15; % Range of frequencies
epsilon = 1e-10; % Small epsilon value
ro = 1; % Define the value of ro
% Define the source and receiver locations
source = [0, 0, 0]; % Source location (x, y, z)
stations = [0.01, 0, 0; 0.02, 0, 0; 0.03, 0, 0; 0.04, 0, 0; 0.05, 0, 0]; % Receiver locations (x, y, z)
% Calculate -Im G11 for different frequencies and stations
results = zeros(size(stations, 1), length(frequencies));
for i = 1:size(stations, 1)
receiver = stations(i, :); % Receiver location (x, y, z)
distance = norm(receiver - source); % Euclidean distance between source and receiver
gamma = (receiver - source) / distance; % Unit vector from source to receiver
gamma = repmat(gamma, length(frequencies), 1); % Repeat gamma for each frequency
for j = 1:length(frequencies)
omega = 2 * pi * frequencies(j);
q = omega / alpha;
f1 = (beta^2 / alpha^2) * (1 - 1j * 2 ./ (q * distance + epsilon) - 2 ./ (q^2 * distance^2 + epsilon)) * exp(-1j * q * distance);
f2 = (beta^2 / alpha^2) * (1j ./ (q * distance + epsilon) + 1 ./ (q^2 * distance^2 + epsilon)) * exp(-1j * q * distance);
results(i, j) = calculate_G11_imag([f1, f2], gamma(j, :), omega, ro, alpha, beta);
end
end
% Plotting
figure;
for i = 1:size(stations, 1)
plot(frequencies, -imag(results(i, :)), 'DisplayName', sprintf('Station: %s', mat2str(stations(i, :))));
hold on;
end
hold off;
xlabel('Frequency');
ylabel('-Im G11');
title('Variation of -Im G11 for Different Stations');
legend('Location', 'northeast');
grid on;
ylim([-1, 10]);
% Define the function to calculate -Im G11
function result = calculate_G11_imag(f, gamma, omega, ro, alpha, beta)
size(f)
size(gamma)
result = -omega / (12 * pi * ro) * (1 / (alpha^3) + 2 / (beta^3)) * sum(f .* gamma);
end
0 件のコメント
回答 (2 件)
Image Analyst
2023 年 5 月 29 日
Put the fuunction definition at the END of your script, not near the beginning. Then you need to CALL IT, passing it all the arguments it needs.
Here is the debugging help you asked for:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Gamma Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!