sensor_depths = sort(rand(1, M) * max_depth);
zm = dz (dz/2) + (0:N-1) * dz
true_velocity_model = 1000 + 80 * zm;
true_data = true_velocity_model * ones(1, M);
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
layer_top = (i - 1) * dz;
G(:, i) = (sensor_depths >= layer_top) & (sensor_depths < layer_bottom);
noisy_data = true_data + noise;
slowness_model = pinv(G) * noisy_data;
estimated_velocity_model = 1 ./ slowness_model;
plot(true_velocity_model, zm, 'b', 'LineWidth', 2);
title('True Velocity Model');
xlabel('Velocity (m/s)');
plot(noisy_data, sensor_depths, 'r.', 'MarkerSize', 10);
plot('estimated_velocity_model', zm, 'g', 'LineWidth', 2);
title('Estimated Velocity Model');
xlabel('Velocity (m/s)');
plot(true_velocity_model, zm, 'b', 'LineWidth', 2);
plot('estimated_velocity_model', zm, 'g', 'LineWidth', 2);
legend('True Model', 'Estimated Model');
title('Comparison of True and Estimated Velocity Models');
xlabel('Velocity (m/s)');