need help with my code

1 回表示 (過去 30 日間)
carmen gomez
carmen gomez 2020 年 5 月 28 日
編集済み: Image Analyst 2020 年 5 月 28 日
I have my code almost completed but i need to do a variation plot and i was given three different values for phi. Phi = 0, 45, 85 (degress). My question is how can i add the other values for phi in this code
delta = 35;
phi = 0;
L = 384329*1000;
re = 6376*1000;
Me = 5.98e24;
Mm = 7.34e22;
lambda = [0:5:360];
T1 = (re/4)*(Mm/Me)*(re/L)^3;
T2 = 3*((sind(phi))^2)*(sind(delta))^2-1;
T3 = 3/2*sind(2*phi)*sind(2*delta)*cosd(lambda);
T4 = 3*(cosd(phi))^2*(cosd(delta))^2*(cosd(lambda)).^2;
eta = T1*(T2+T3+T4);
figure(1)
plot(lambda,eta)
grid on
xlabel('\lambda(degrees)')
ylabel('\eta(m)')
title('\eta(m) Vs. \lambda(degrees) when \phi is 0(degrees)')

回答 (1 件)

Image Analyst
Image Analyst 2020 年 5 月 28 日
編集済み: Image Analyst 2020 年 5 月 28 日
Try this:
clc; % Clear the command window.
fprintf('Beginning to run %s.m.\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
delta = 35;
allPhi = [0, 45, 85]
L = 384329*1000;
re = 6376*1000;
Me = 5.98e24;
Mm = 7.34e22;
lambda = [0:5:360];
T1 = (re/4)*(Mm/Me)*(re/L)^3;
for k = 1 : length(allPhi)
phi = allPhi(k);
T2 = 3*((sind(phi))^2)*(sind(delta))^2-1;
T3 = 3/2*sind(2*phi)*sind(2*delta)*cosd(lambda);
T4 = 3*(cosd(phi))^2*(cosd(delta))^2*(cosd(lambda)).^2;
eta = T1*(T2+T3+T4);
subplot(2, 2, k);
plot(lambda,eta, 'b-', 'LineWidth', 2);
grid on
xlabel('\lambda(degrees)', 'FontSize', fontSize);
ylabel('\eta(m)', 'FontSize', fontSize);
% title('\eta(m) Vs. \lambda(degrees) when \phi is 0(degrees)', 'FontSize', fontSize);
caption = sprintf('\\eta(m) Vs. \\lambda(degrees) when \\phi is %.1f(degrees)', phi); % Use double backslashes.
title(caption, 'FontSize', fontSize);
end
g = gcf;
g.WindowState = 'maximized'
fprintf('Done running %s.m.\n', mfilename);

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by