I need a help with my project!!
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 16 de Mayo de 2016
Please show the complete error message, everything in red. Also please show the parameters you are passing to your routine.
Respuesta aceptada
Más respuestas (1)
parth pandya
el 16 de Mayo de 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 comentarios
Abdullah Jizani
el 16 de Mayo de 2016
parth pandya
el 16 de Mayo de 2016
Editada: parth pandya
el 16 de Mayo de 2016
I was referring for using code option in forum not in matlab software.please see image.

Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!