How to fix matrix dimensions
Show older comments
Given the specific values of y, sigmay, and sigmaz (see code), I must calculate them and plot each line on a graph
close all;
clear all;
clc
Q = 1;
y = [10, 20, 30, 40, 50, 65, 80, 100, 200, 300, 400, 500, 650, 800, 1000];
sigmay = [27, 62, 115, 165, 210];
sigmaz = [14, 38, 105, 250 450];
u = 2;
for j = 1:y
for k = 1:sigmay
for l = 1:sigmaz
C = (Q./pi.*sigmay.*sigmaz.*u).*exp(-0.5.*(y./sigmay).^2); %% this is where the error is at%%
end
end
end
plot(y,C)
title('Excercise 1')
xlabel('distance (m)')
ylabel('concentrations')
grid on
As you can see, I tried using the ./ or .* but, it didn't work.
4 Comments
You seem to be mixing up loops with vectorized code. How about:
Q = 1;
y = [10, 20, 30, 40, 50, 65, 80, 100, 200, 300, 400, 500, 650, 800, 1000];
sigmay = [27, 62, 115, 165, 210];
sigmaz = [14, 38, 105, 250 450];
u = 2;
C = (Q./pi.*sigmay.*sigmaz.*u).*exp(-0.5.*(y(:)./sigmay).^2)
Jonathon Klepatzki
on 10 Apr 2024
Edited: Jonathon Klepatzki
on 10 Apr 2024
Stephen23
on 10 Apr 2024
"Any suggestions?"
Do you have a reference for the formula?
Jonathon Klepatzki
on 10 Apr 2024
Accepted Answer
More Answers (0)
Categories
Find more on Aerospace Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!