Azzera filtri
Azzera filtri

How to put numbers into a new array?

1 visualizzazione (ultimi 30 giorni)
YuChe Kao
YuChe Kao il 9 Mar 2018
Risposto: Guillaume il 9 Mar 2018
>>I have created a script that I can get lots of different values of G(i) and drawn a plot of G(i) and t. Then, I want to create an array that assembles all the G(i) in it. Could anyone can please help me how to do this?
My script is as below:
t=0:0.02:5;
for i=1:numel(t);
T(i)=170-22*t(i);
if T(i)>=120;
G(i)=((3.98*10^7)*exp(-1500/(1.987*(T(i)-30)))*exp((-2.55*10^5)*(T(i)+273.15+212+273.15)/(2*(T(i)+273.15)*(T(i)+273.15)*(212-T(i)))))/60;
else
G(i)=((4.81*10^11)*exp(-1500/(1.987*(T(i)-30)))*exp((-5.51*10^5)*(T(i)++273.15+212+273.15)/(2*(T(i)+273.15)*(T(i)+273.15)*(212-T(i)))))/60;
end
end
plot(t,G);
Thanks a lot in advance

Risposte (1)

Guillaume
Guillaume il 9 Mar 2018
I'm not clear on your question. the array that assembles all the G(i) is G.
Note that 3.98*10^7 is better written as 3.98e7. It faster for matlab to compute and in my opinion easier to read
Also, note that the loop is completely unnecessary:
t = 0:0.02:5;
T = 170 - 22*t;
Gbelow = 4.81e11*exp(-1500/(1.987*(T-30).*exp(-5.51e5*(T+273.15+212.273.15)./(2*(T+273.15).*(T+273.15).*(212-T)))/60;
Gabove = 3.98e7*exp(-1500/(1.987*(T-30).*exp(-2.55e5*(T+273.15+212.273.15)./(2*(T+273.15).*(T+273.15).*(212-T)))/60;
G = Gbelow;
G(T>=120) = Gabove(T>=120);
plot(t, G);

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by