epheterson

09-03-2009, 07:58 PM

Please help me get the basics here..

I have to use Euler's Method to develop a plot and I've come this far:

function y = hw1_8

% Function to determine water level in tank as a function of time

%

% Inputs: a = Cross-Sectional Surface Area

% Q = Flow rate

%

% Outputs: Water level as a function of time

a = 1200;

q = 500;

y = 0;

t = 0;

while t <= 10

y = y + [3*q/a*sin(t)^2 - q/a]*(.5);

fprintf('time = %3.1f y = %5.2f\n', t, y);

t = t+.5;

end

end

It returns a list of the correct values that I need, but by using my method, it dumps all of the previous values of y. How can I have it store the values as an array so that I can plot t vs. y after I'm done?

Any help is greatly appreciated, I'd love to be good at Matlab!

I have to use Euler's Method to develop a plot and I've come this far:

function y = hw1_8

% Function to determine water level in tank as a function of time

%

% Inputs: a = Cross-Sectional Surface Area

% Q = Flow rate

%

% Outputs: Water level as a function of time

a = 1200;

q = 500;

y = 0;

t = 0;

while t <= 10

y = y + [3*q/a*sin(t)^2 - q/a]*(.5);

fprintf('time = %3.1f y = %5.2f\n', t, y);

t = t+.5;

end

end

It returns a list of the correct values that I need, but by using my method, it dumps all of the previous values of y. How can I have it store the values as an array so that I can plot t vs. y after I'm done?

Any help is greatly appreciated, I'd love to be good at Matlab!