Why F vs T graph are not plotted , it shows only blank figure and how i can get all the values of F and T in the workspace as it shows only last value.

1 visualizzazione (ultimi 30 giorni)
c1 = 27.742*10.^8;
c2 = 1.43878*10.^4;
sigma = 5.67*10.^-8;
T = 5780;
lamda_1 = 8;
lamda_2 = 13;
for T=-10:5:30
fun = @(lambda) c1./lambda.^5.*(exp(c2./(lambda * T+273))-1);
F = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4)
plot(T,F)
hold on
grid
end
xlabel('Temperature')
ylabel('Fraction in atmospheric window)')
title('Fraction of the radiation emitted in the atmospheric window as a function of temperature')
legend('T=-10','T=-5','T=0','T=5','T=10','T=15','T=20','T=25','T=30')
hold off

Risposta accettata

Ameer Hamza
Ameer Hamza il 27 Set 2020
You are not specifying the marker type in plot() and also you are not saving vaues of F at each iteration
c1 = 27.742*10.^8;
c2 = 1.43878*10.^4;
sigma = 5.67*10.^-8;
lamda_1 = 8;
lamda_2 = 13;
Tv = -10:5:30;
F = zeros(size(Tv));
count = 1;
for T=Tv
fun = @(lambda) c1./lambda.^5.*(exp(c2./(lambda * T+273))-1);
F(count) = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4);
plot(T, F(count), '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
grid
count = count + 1;
end
xlabel('Temperature')
ylabel('Fraction in atmospheric window)')
title('Fraction of the radiation emitted in the atmospheric window as a function of temperature')
legend('T=-10','T=-5','T=0','T=5','T=10','T=15','T=20','T=25','T=30')
hold off
  1 Commento
Sarvjeet Singh
Sarvjeet Singh il 4 Ott 2020
error shows 'Index exceeds matrix dimensions.', how to fix
clc
clear all
%%%%%%%%%%%%%%%%Steepest Descent %%%%%%%%%%%%%%%5
ao=1;
bo=0.2;
co=0.1;
x = [0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8];
y= [1.196 1.379 1.581 1.79 2.013 2.279 2.545 2.842 3.173 3.5];
Sum=0
for i=1:10
S=((y(i)-(ao.*(exp(bo*x(i))+co*x(i)).^2)));
Sum=Sum+S
end
Initial_S=Sum
coeffi_mat=[1 0.2 0.1];
%now calculating next coefficints and then finding new S, till the value of S<0.01
j=1
while S>0.01
S_to_a=0;
S_to_b=0;
S_to_c=0;
for i=1:10
Part_1=(y(i)-(coeffi_mat(j,1)).*exp(coeffi_mat(j,2))*x(i));
S_to_a_sum_2=-1.*exp(coeffi_mat(j,2))*x(i);
S_to_a_sum= Part_1.*S_to_a_sum_2;
S_to_a= S_to_a+ S_to_a_sum;
S_to_b_sum_2=-(coeffi_mat(j,1)).*x(i).*exp(coeffi_mat(j,2))*x(i);
S_to_b_sum= Part_1.*S_to_b_sum_2;
S_to_c_sum_2=-x(i);
S_to_c=Part_1.*S_to_c_sum_2;
end
S_to_a_final=2.*S_to_a
S_to_b_final=2.*S_to_b
S_to_c_final=2.*S_to_c
%%%%%%%%%5calculating gradient%%%%%%%%5
grad=sqrt((S_to_a_final).^2+(S_to_b_final).^2+(S_to_c_final).^2)
%%%%%%%%%%%calculating unit vectoresb%%%%%%%%555
uv_a=S_to_a_final/grad
uv_b=S_to_b_final/grad
uv_c=S_to_c_final/grad
%%%%%%%%calculating new coefficient %%%%%%%
%%%del=0.02
a= coeffi_mat(i,1)-(0.02*uv_a)
b= coeffi_mat(i,2)-(0.02*uv_b)
c= coeffi_mat(i,3)-(0.02*uv_c)
%%%% Appending new coefficient in coefficient matrix %%%%%%%%%5
coeffi_mat=[coeffi_mat;a,b,c]
%%%%%%%% calculating the value of S %%%%%%%%
for i=1:10
S_1=y(i)
S_2= (coeffi_mat(i+1,1).*exp(coeffi_mat(j+1,2).*1)+coeffi_mat(j+2,3).*1)
S=((S_1)-(S_2))^2
end
end
%%when while loop will end, final value of S will be found then value of a,b,c will be expected as
final_a=coeffi_mat(end,1)
final_b=coeffi_mat(end,2)
final_c=coeffi_mat(end,3)

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 27 Set 2020
for T=-10:5:30
Inside the body of the for loop, at any one time, T will be a scalar value. The first iteration it would be the scalar value -10, the second time it would be the scalar value -5, and so on.
F = integral(fun,lamda_1,lamda_2)./(sigma.*(T+273)^4)
The result of integral() is always a scalar, unless you have passed in the option 'ArrayValued', true
plot(T,F)
so there you are plot() with a scalar T and scalar F. But by default, plot() is only for drawing lines, and in order to draw a line, plot needs to be be passed something that includes at least two adjacent finite values. With scalar T and scalar F, there is only the one point, when it needs at least two points to join to create a line.
plot() does not "remember" the previous points that have already been drawn to automatically join them together -- that would typically be the wrong thing to do.
There are several different things you can do:
  • you can plot(T, F, '*') which will not create any lines, but will at least put a * marker at every point
  • you can keep a record of each T and F value, storing the values inside vectors inside the loop, and then plot afterwards with no plot inside the loop. I recommend that you read https://www.mathworks.com/matlabcentral/answers/504285-for-loop-for-non-consecutive-values-in-an-array#answer_414399
  • you can keep track of the handle of the "chart line object" (line()) that plot() outputs, and then each iteration of the loop, pull out the XData and YData properties of that line() object, and add the new T and F point to the ends of those lists, and set those as the new values for the XData and YData properties. The line() object is the internal representation of which points are to be drawn, so updating the XData and YData properties would cause it to extend the existing line
  • you can use animatedline() and addpoints() to hide the details of the kind of XData / YData tracking that I mentioned above.
Except for very long loops where you want to see plotting results before the function finishes, I recommend taking the approach of recording the values and plotting afterwards.

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by