انتقال حرارت یک بعدی در یک استوانه
۲٫ clc
۳٫ %input data
۴٫ n=input(‘Enter number of nod: ‘);
۵٫ r=input(‘Enter radius of cylinder: ‘);
۶٫ T_f=input(‘Enter temperature of fluid: ‘);
۷٫ k=input(‘Enter thermal conductivity of cylinder: ‘);
۸٫ h=input(‘Enter convection coefficient of fluid: ‘);
۹٫ g=input(‘Enter generation of cylinder: ‘);
۱۰٫ %calculation parameter
۱۱٫ dr=r/(n-1);
۱۲٫ %calculate temperature distribution
۱۳٫ T=zeros(1,n);
۱۴٫ iteration=0;
۱۵٫ R=1;
۱۶٫ while R~=0
۱۷٫ TT=T;
۱۸٫ T=(((n-.5)*T(n-1))+((g*n*dr^2)/(2*k))+(h*n*dr*T_f)/k)/(((n-.5)+(h*n*dr)/k));
۱۹٫ for i=(n-1):-1:2
۲۰٫ T(i)=(((i-.5)*T(i-1))+((i+.5)*T(i+1))+(g*i*dr^2)/k)/(2*i);
۲۱٫ end
۲۲٫ T(1)=T(2)+(g*dr^2)/(2*k);
۲۳٫ iteration=iteration+1;
۲۴٫ R=sum(abs(T-TT));
۲۵٫ end
۲۶٫ %output
۲۷٫ iteration
۲۸٫ T
۲۹٫ plot(T)
برای محاسبه توزیع دمای یک استوانه که در یک سیال قرار گرفته است کد های زیر را در یک M-File در متلب وارد کنید:
۱٫ clear all۲٫ clc
۳٫ %input data
۴٫ n=input(‘Enter number of nod: ‘);
۵٫ r=input(‘Enter radius of cylinder: ‘);
۶٫ T_f=input(‘Enter temperature of fluid: ‘);
۷٫ k=input(‘Enter thermal conductivity of cylinder: ‘);
۸٫ h=input(‘Enter convection coefficient of fluid: ‘);
۹٫ g=input(‘Enter generation of cylinder: ‘);
۱۰٫ %calculation parameter
۱۱٫ dr=r/(n-1);
۱۲٫ %calculate temperature distribution
۱۳٫ T=zeros(1,n);
۱۴٫ iteration=0;
۱۵٫ R=1;
۱۶٫ while R~=0
۱۷٫ TT=T;
۱۸٫ T=(((n-.5)*T(n-1))+((g*n*dr^2)/(2*k))+(h*n*dr*T_f)/k)/(((n-.5)+(h*n*dr)/k));
۱۹٫ for i=(n-1):-1:2
۲۰٫ T(i)=(((i-.5)*T(i-1))+((i+.5)*T(i+1))+(g*i*dr^2)/k)/(2*i);
۲۱٫ end
۲۲٫ T(1)=T(2)+(g*dr^2)/(2*k);
۲۳٫ iteration=iteration+1;
۲۴٫ R=sum(abs(T-TT));
۲۵٫ end
۲۶٫ %output
۲۷٫ iteration
۲۸٫ T
۲۹٫ plot(T)
تصویری از محیط اجرای کد در متلب:
پیوست ها
آخرین ویرایش: