Hello, I am not really sure the best way to describe this problem… Essentially what I want to do is solve a function that outputs an array, while in a for loop. If you look at the code, lines 45 through 48 are the parts in question. Rather than solving dT three separate times, I would like to solve it within a for loop that will output something like T(i), then call an entire column and plot it.
clc;clear all;close all;%%Solution Outline
%%Assumptions
%%Paranmeters
% nio for niobium
nio.d = 0.01; % [m] Diameter of the sphere
nio.Ti = 900 + 273; % [K] Initial Temperature
nio.Tf = 300 + 273; % [K] Final Temperature
nio.rho = 8600; % [kg/m^3] Density
nio.c = 290; % [J/kg K] Specific Heat
nio.k = 63; % [W/m K] Thermal Conductivity
nio.Tinf = 25 + 273; % [K] Assumed Room Temperature
nio.A = 4*pi*(nio.d/2)^2; % [m^2] Surface Area of the Sphere
nio.V = 4/3*pi*(nio.d/2)^3;%[m^3] Volume of Sphere
nio.eps = 0.6; % Emissivity
h = [10,200,500]; % [W/m^2 K] Convection Coefficient
sigma = 5.67e-8; % Stefan Boltzmann constant
%%Calculations
% The first step is to create a plot with the various h values
% How can I do the following in a for loop?
[t1,T1] = dT(nio,h(1)); [t2,T2] = dT(nio,h(2));[t3,T3] = dT(nio,h(3));plot(t1,T1,t2,T2,t3,T3);%%Sub Function
function [t,T] = dT (nio,h)dT = @(t,T) ( -h*nio.A*(T-nio.Tinf) - nio.A*sigma*nio.eps*(T^4 - ... nio.Tinf^4)) / (nio.rho*nio.V*nio.c);[t,T] = ode45 (dT, [0,60] , [nio.Ti]);endend
Best Answer