# Math Help - need help with matlab function

1. ## need help with matlab function

ok for some reason i cant get this function to work.

in one file i have
t=[0:.1:30];
x=postion(t)
plot(t,x)

and in the other file i have

function x=postion(t)
if 0<=t<=10
y=.5*t^2;
elseif 10<=t<=20
y=.5*t^3-t^2+15*t-50;
elseif 20<=t<=30
y=.0025*t^4-.15*t^3+135*t-1650;
end
end

and i cant get it to work

2. Originally Posted by truong123
ok for some reason i cant get this function to work.

in one file i have

Code:
t=[0:.1:30];
x=postion(t)
plot(t,x)
and in the other file i have

Code:
function x=postion(t)
if 0<=t<=10
y=.5*t^2;
elseif 10<=t<=20
y=.5*t^3-t^2+15*t-50;
elseif 20<=t<=30
y=.0025*t^4-.15*t^3+135*t-1650;
end
end
and i cant get it to work
When you run it what error message do you get? Have you considered running this under debug?

It might help if your return value in the function was something you have calculated though.

CB

3. i get errors in both files. in the 1st file i get

??? Undefined function or method 'postion' for input arguments of type 'double'.

Error in ==> g233x23 at 8
x=postion(t)

and in the function file i get

??? Input argument "t" is undefined.

Error in ==> position at 2
if 0<=t<=10