On 5/7/2011 6:02 AM, munkey wrote:
> I am trying to plot a grph of height versus time with three separate conditions the conditions are;
>
> when t<=36
>
> h=nthroot(((9*F*t)/pi),3);
>
>
> when 36<t<=100
>
> h=((F*t)/(pi*r^2))+H1;
>
>
> when t>100
>
> h=HT
>
>
> where HT,H1,F and r are all known and definsed variables. I have defined
> t as a range of variable between 0 and 150 and used the if and else loops
> to try and define which formula to use for which t but it just uses the
> formula that fits the condition for the heighest value of t.
>
> this is my script
>
> %Coursework rough
>
> clear all
> clc
>
> F=6.2;
>
> H1=8.66; %Height of conical section
> ConeT=(H1^3*pi)/(9*F); %Time taken to fill volume of cylinder
>
> r=5; %radius of cylinder
> H2=8; %height of the cylinder
> CylinderT=(8*pi*r^2)/F; %Time taken to fill volume of cylinder once cone is full
>
> HT=H1+H2; %Total height of the hopper
> HopT=ConeT+CylinderT; %Total time to fill the volume of the hopper
>
>
>
> t=[0 0.25 0.5 0.75 1 2 3 5 10 15 35 37];
> hold on
> if t<=ConeT;
> h=nthroot(((9*F*t)/pi),3);
>
> plot(t,h);
>
> elseif ConeT<t<=CylinderT;
> h=((F*t)/(pi*r^2))+H1;
>
> plot(t,h);
>
>
> else t>HopT;
> h=HT;
>
> plot(t,h)
>
> end
>
> hold off
you cant type 'if t<number', t is an array !
try this:

clear all
clc
figure(1); hold on;
F=6.2;
H1=8.66; %Height of conical section
ConeT=(H1^3*pi)/(9*F); %Time taken to fill volume of cylinder
r=5; %radius of cylinder
H2=8; %height of the cylinder
CylinderT=(8*pi*r^2)/F; %Time taken to fill volume of cylinder once cone is full
HT=H1+H2; %Total height of the hopper
HopT=ConeT+CylinderT; %Total time to fill the volume of the hopper
t1=0:.1:ConeT;
plot(t1,nthroot(((9*F*t1)/pi),3));
t2=ConeT:.1:CylinderT;
plot(t2,((F*t2)/(pi*r^2))+H1);
t3=CylinderT:.1:HopT;
plot(t3,ones(1,length(t3))*HT);

Nasser
