Will the program run

9 vues (au cours des 30 derniers jours)
Tanu Garg
Tanu Garg le 29 Mai 2021
e=8.854*10^(-12); for l=1:1:5 , z=[0.00478 0.00828 0.011 0.015 0.018] for s=[19.5101 30.1388 38.7676 47.6357 64.1442] , h=[120000 200000 380000 540000 680000] , o=[0.9990 0.9961 0.9940 0.9982 0.9991] f=7.486.*sqrt((l.*(l+1)).*((1-(h/6378.1))/(o+j.*(s/(e.*2.*pi.*z))))); plot(h,f); end xlabel('schumann resonance frequency f'); ylabel('altitude h'); title('SR');
  1 commentaire
Jan
Jan le 29 Mai 2021
Modifié(e) : Jan le 29 Mai 2021
I've removed the duplicate question.
Please format your codeto make it readable: One command per line and use the Code style selected from the toolbar. If you have done this, you can simply press the green triangle to let the code run directly here in the forum. Then you can see the answer by your own.

Connectez-vous pour commenter.

Réponses (2)

Image Analyst
Image Analyst le 29 Mai 2021
Modifié(e) : Image Analyst le 29 Mai 2021
No it will not run.
  1. You have no closing end on your (badly-named) l loop
  2. You have no hold on after plot(h, f)
  3. You have not defined j. If it's the imaginary variable use 1j like the editor hint tells you.
  4. Not sure what your s loop is doing. It will iterate over each value of s one at a time but in your formula you're using the whole vector of s values.
  5. the (also badly-named) o is in the denominator (along with vector s) and it's a vector not a scalar so you'd need to have ./ instead of / to do an elemente-by-element divide.
e=8.854*10^(-12);
for l=1:1:5
z=[0.00478 0.00828 0.011 0.015 0.018]
for s=[19.5101 30.1388 38.7676 47.6357 64.1442]
h=[120000 200000 380000 540000 680000]
o=[0.9990 0.9961 0.9940 0.9982 0.9991]
f=7.486.*sqrt((l.*(l+1)).*((1-(h/6378.1))/(o+j.*(s/(e.*2.*pi.*z)))));
plot(h,f);
end
xlabel('schumann resonance frequency f');
ylabel('altitude h');
title('SR');
Perhaps this is closer but I really have no idea what you want to do:
e=8.854*10^(-12);
allz=[0.00478 0.00828 0.011 0.015 0.018]
allh=[120000 200000 380000 540000 680000]
allo=[0.9990 0.9961 0.9940 0.9982 0.9991]
alls=[19.5101 30.1388 38.7676 47.6357 64.1442]
j = 42;
for l = 1 : 5
for k = 1 : length(alls)
thiss = alls(k);
thiso = allo(k);
thisz = allz(k);
thish = allh(k);
f = 7.486.*sqrt((l.*(l+1)).*((1-(thish/6378.1)) ./ (thiso+j.*(thiss ./ (e.*2.*pi.*thisz)))));
plot(thish,f, 'b.');
hold on;
end
xlabel('Schumann resonance frequency f');
ylabel('Altitude h');
title('SR');
end
grid on;

David Hill
David Hill le 29 Mai 2021
No loops needed. I assume your j is imaginary and that you only want to plot the real part of f.
e=8.854*10^(-12);
l=1:5;
z=[0.00478 0.00828 0.011 0.015 0.018];
s=[19.5101 30.1388 38.7676 47.6357 64.1442];
h=[120000 200000 380000 540000 680000];
o=[0.9990 0.9961 0.9940 0.9982 0.9991];
f=7.486*sqrt((l.*(l+1)).*((1-(h/6378.1))./(o+1i*(s./(e*2*pi*z)))));
plot(h,real(f));
xlabel('schumann resonance frequency f');
ylabel('altitude h');
title('SR');

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by