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
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Warning: Colon operands must be real scalars. This warning will become an error in a future release.
Arrays have incompatible sizes for this operation.
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

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)
C = 15x5
1.0e+04 * 0.0225 0.1480 0.7658 2.6212 6.0092 0.0183 0.1424 0.7572 2.6068 5.9888 0.0130 0.1334 0.7430 2.5830 5.9550 0.0080 0.1218 0.7236 2.5500 5.9079 0.0043 0.1084 0.6994 2.5082 5.8479 0.0013 0.0866 0.6552 2.4300 5.7347 0.0003 0.0652 0.6035 2.3348 5.5950 0.0000 0.0408 0.5267 2.1855 5.3712 0.0000 0.0008 0.1694 1.2597 3.8225 0.0000 0.0000 0.0256 0.5029 2.1685
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Jonathon Klepatzki
Jonathon Klepatzki 2024년 4월 10일
편집: Jonathon Klepatzki 2024년 4월 10일
I originally had just the equation C listed then tried it with a for loop. I just tried your method and it worked great. However, concentration values are way too large. They actually need to be at an order of 10^-6 or lower. Any suggestions?
Stephen23
Stephen23 2024년 4월 10일
"Any suggestions?"
Do you have a reference for the formula?
Jonathon Klepatzki
Jonathon Klepatzki 2024년 4월 10일
Just this, C = (Q/pi*sigmaz*sigmay*u)*exp(-1/2(y/sigmay)^2)

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

 채택된 답변

the cyclist
the cyclist 2024년 4월 10일
이동: Rik 2024년 4월 11일

0 개 추천

In this expression
Q/pi*sigmaz*sigmay*u
only pi is going to be in the denominator.
Since your expression bears some resemblance to the PDF of a normal distribution, I expect that at least sigmaz and sigmay are also supposed to be in the denominator. Probably u as well.
I expect that you actually need
Q/(pi*sigmaz*sigmay*u)
which would give
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)
C = 15x5
1.0e-03 * 0.3931 0.0667 0.0131 0.0039 0.0017 0.3200 0.0641 0.0130 0.0038 0.0017 0.2271 0.0601 0.0127 0.0038 0.0017 0.1405 0.0549 0.0124 0.0037 0.0017 0.0758 0.0488 0.0120 0.0037 0.0016 0.0232 0.0390 0.0112 0.0036 0.0016 0.0052 0.0294 0.0103 0.0034 0.0016 0.0004 0.0184 0.0090 0.0032 0.0015 0.0000 0.0004 0.0029 0.0019 0.0011 0.0000 0.0000 0.0004 0.0007 0.0006
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
This looks to be in the ballpark of what you expected.

댓글 수: 1

Jonathon Klepatzki
Jonathon Klepatzki 2024년 4월 10일
이동: Rik 2024년 4월 11일
That actually fixed it. It's been one of those days. Thank you @Stephen23@the cyclist

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2024년 4월 10일

이동:

Rik
2024년 4월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by