MATLAB question: Use nested for loops to perform the following exercises. Do not
ID: 3035047 • Letter: M
Question
MATLAB question:
Use nested for loops to perform the following exercises. Do not use mean. Create the 3-D function: T(x, y, z) = x^2 + 2y + 3z^2 in a rectangular domain with x [-3:0.1:3]; y = [:-1:0.1:1] and z [-2:0.1:2]. Matrix T should have the dimension of length (x) by length (y) by length (z). Set p3a=T Compute the average values of T along the z-direction and put the answer into p3b The answer should be a 2-D matrix with the dimension of length(x) by length (y). Compute the average values of T over the x-y planes and put the answer into p3c. The answer should be a vector with the dimension of length(z) Compute the average value of T over the entire rectangular domain and put the answer into p3d. The answer should be a single number.Explanation / Answer
Initialize Random Sampling Values and Loop MCnumb=500; % number of monte carlo iterations MCits=(0:MCnumb); % generate MC loop variable
Y0=0.42 % mg VSSa/mgBODL clear Y; % Clear Variable Y(1)=Y0 % Initial value for yield
for j=1:length(MCits-1), %Set up for loop for MC
Y(j+1)=(Y(j)*rand(1)/Y(j)); end
%Script that demonstrates Euler integration for a Monod Model % The problem set to be solved is: % S'=((-q*S(t))/(K+S(t)))*X(t); % X'=Y*(((q*S(t))/(K+S(t))-b-(k2h/1.42))*X(t);
% Define Parameters; q=10; % mgBODl/mgVSSa-day K=20; % mgBODl/l b=0.15; % 1/day k2h=0.09; % mgCODP/mgVSSa-day
%Define Initial Conditions; S0=500; % mg/L X0=20; % mg/L
%Initialize Time Set and Step Size
h=0.01; %h is the time step. tend=2; %tend is end of approximation in days t=.1:h:tend; %initialize time variable.
clear Substrate; %wipe out old variables. clear Biomass;
Sub(1)=S0; %initial condition (same for approximation). Biomass(1)=X0;
for j=1:length(Y)-1,
for i=1:length(t)-1, %Set up "for" loop. Srate(i)=-((q*Sub(i))/(K+Sub(i)))*Biomass(i); %Calculate derivative (rate); Xrate(i)=Y(j)*((q*Sub(i))/(K+Sub(i))-b-(k2h/1.42))*Biomass(i);
Sub(i+1)=Sub(i)+h*Srate(i); %Estimate new concentrations; Biomass(i+1)=Biomass(i)+h*Xrate(i);
Substrate(j+1)=Sub(i);
end
SJ(j)=vertcat(Substrate(j),Substrate(j+1)) end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.