I need a help with my project!!
Show older comments
Hello everyone,
I have a problem writing my function on matlab and it simply shows that when I start from v(1.1)is not possible and it should be a positive integer.
it is a very simple function including a loop but it is required. this function is supposed to calculate the velocity and time for each height.
this is what I have written so far.
function y=freefall(v,t)
g=9.81;
%Gravity in m^2/s
h=input('Please Enter the hieght\n')
for k=1:h
v(k)=sqrt(2*g*k);
end
for k=1:h
t(k)=sqrt(2*k/g);
end
plot(t,v)
xlabel('Time (s)')
ylabel('Velocity
(m/s)')
title('Free fall: velocity vs time')
1 Comment
Walter Roberson
on 16 May 2016
Please show the complete error message, everything in red. Also please show the parameters you are passing to your routine.
Accepted Answer
More Answers (1)
parth pandya
on 16 May 2016
Hi Abdullah, Please Format code using '{}Code' option.It will be easy.
I just want to give you few pointers regarding your question.
1) Why are you passing v & t ?? As you are doing nothing with that variables in function.
2) Also I will recommend pre allocate memory for v & t. like:
v = zeros(h,1);
t = zeros(h,1);
3) If you save your function file with same function name,then code is running without error.
2 Comments
Abdullah Jizani
on 16 May 2016
parth pandya
on 16 May 2016
Edited: parth pandya
on 16 May 2016
I was referring for using code option in forum not in matlab software.please see image.

Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!