Simple problem using for loop/array

1 回表示 (過去 30 日間)
JaydudeZ
JaydudeZ 2016 年 10 月 14 日
編集済み: Ganesh Hegade 2016 年 10 月 25 日
Hello, I am quite new to Matlab and have read through Help sections, forums etc, but I still cannot get my basic code to correctly execute multiplying a constant by array (I have tried matrix too) and give me the answer that is correct.
clear all; clc
A=0.4; % bond albedo
AU=1.496*10^11
row=5.67*10^-8; % boltz const
L=3.84*10^26; % lum sun
num1=(1-A)*L;
% calc denominator
den=16*pi*row;
temp_range=[373.15; 273.15] %matrix 2x1
% temp_range=[373.15 273.15] %array
k=den.*((temp_range).^4)
% calc habitable zone
distance=(num1/k).^0.5
hab=distance/AU
% second attempt
%
% for i=temp_range;
% k=den.*(i.^4)
% end
% d=(num1/k).^0.5
% hab=d/AU
% disp(hab)
% code
end
The output of this gives me answers to one of the temperature range only, either 0.4 or 0.8, with the other value in the array Or matrix (tested both) being zero. eg.Output gives ;
% hab =
0.4316 0
and the same result but with a 2x1 matrix, that second value should be 0.8xxx etc. The second attempt yields exactly the same result.
What steps have I done wrong/missed completely? (I have not provided the entire code, just a snippet for the problem seen, if required I will provide the constants missing/entire code)
Kind regards,
Jay
  2 件のコメント
Ganesh Hegade
Ganesh Hegade 2016 年 10 月 14 日
What is the value of 'row'?
JaydudeZ
JaydudeZ 2016 年 10 月 14 日
編集済み: JaydudeZ 2016 年 10 月 14 日
Edited, see code again- row was Stefan Boltzman constant

サインインしてコメントする。

採用された回答

Ganesh Hegade
Ganesh Hegade 2016 年 10 月 25 日
編集済み: Ganesh Hegade 2016 年 10 月 25 日
Hi,
Please use this. It gives the output as you have requested above.
clc;
A=0.4; % bond albedo
AU=1.496*10^11;
row=5.67*10^-8; % boltz const
L=3.84*10^26; % lum sun
num1=(1-A)*L;
% calc denominator
den=16*pi*row;
temp_range=[373.15; 273.15]; %matrix 2x1
% temp_range=[373.15 273.15] %array
k=den.*((temp_range).^4);
% calc habitable zone
for i = 1:length(k)
distance(i)=(num1/k(i)).^0.5;
end;
hab=distance/AU;
Thanks.

その他の回答 (2 件)

Pritesh Shah
Pritesh Shah 2016 年 10 月 14 日
May be, you can you debug your program. Give completer code to give solution

JaydudeZ
JaydudeZ 2016 年 10 月 15 日
bump

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by