How to define a variable as a condition of other variables

조회 수: 8 (최근 30일)
Madison Cocker
Madison Cocker 2022년 3월 16일
편집: Torsten 2022년 3월 16일
Hi there, I am working on a project for an environmental science class where I need to plot the change in temperature as a function of the change in the solar constant from 1000wm-2 to 2000wm-2. The equation I need to use is TSI=r^2*Stefan-Boltzmann constnat*T^4 / L^2, where I know the values of r, SB constant, and L, but I'm not sure how to write the program such that it calculates a new temperature for each TSI value between 1000-2000, if that makes sense. I have an intial condition for the temperature as well. I assume I need a for loop somewhere, but I'm not sure how to start writing the equation for finding each temperature.
Thanks very much.
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2022년 3월 16일
What have you tried so far? You'll find the community happy to help you fix your code, but more hesitant to code your assignment for you.
Madison Cocker
Madison Cocker 2022년 3월 16일
Hi There, thank you for your response. I defined all my variables like so, and when I attempted to define T and TSI was where my problem arose because they are functions of each other. I hope that helps
L=1.5*10^11
r=6.95*10^8
SB=5.67*10^-8
>> TSI=(r.^2 .* SB .*T.^4)/L.^2
Unrecognized function or variable 'T'.
>> T=TSI/SB
Unrecognized function or variable 'TSI'.

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

채택된 답변

Torsten
Torsten 2022년 3월 16일
편집: Torsten 2022년 3월 16일
dTSI = r^2*SBC*4*T^3*dT/L^2
dT = dTSI*L^2/(r^2*SBC*4*T^3)
dT/dTSI = L^2/(r^2*SBC*4*T^3)
Thus in MATLAB:
r = ...;
SBC = ...;
L = ...;
TSI = 1000:1:2000;
T = (TSI*L^2/(r^2*SBC)).^0.25
dTdTSI = L^2./(r^2*SBC*4*T.^3)
plot(TSI,dTdTSI)
I'm still not 100% certain if this is really what you are told to plot, but I guess it's correct.

추가 답변 (2개)

David Hill
David Hill 2022년 3월 16일
TSI=1000:2000;
T=(TSI/r^2/SB_constant*L^2).^.25;

Enrico Gambini
Enrico Gambini 2022년 3월 16일
편집: Enrico Gambini 2022년 3월 16일
Hi.
Generally matlab "doesn't like" for loops like other programming languages. That's because in most of the cases there is the possibility to indicize an array in a simpler (and faster) way.
Hence, for your specific problem I propose:
r=input("Insert the value of r:\n");
L=input("Insert the value of L:\n");
Sb_const=input("Insert the value of Stefann-Boltzmann constant :\n");
TSI=[1000:2000];
T=(TSI*L^2/(r^2*Sb_const)).^(1/4); %I inverted the formula and it is computing the Temperature at an interval of 1 W/m2 between 1000 and 2000
plot(TSI,T); %plot TSI vs T

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by