Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How do I deal with this function handel error?

1 Ansicht (letzte 30 Tage)
Ruten9
Ruten9 am 25 Okt. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
my height file:
function h = height(t)
h = @(t) ((-9.8).*(2.^(-1))).*(t.^2) + 125.*t + 500;
h(h<0) = 0;
if h(t) <0
then h=0
end
end
My main file:
clear all; clc;
t = 0:.01:35;
h = height(t)
%Part C (maxima)
[xpsudeomax,ymax] = max(h(t));
xrealmax = t(ymax);
maxfunction = [xrealmax,ymax];
%fminbnd function
[xmax2,ymaxpsudeo]= fminbnd(@(t) (-1.*h(t)),0,30);
yrealmax = -1.*ymaxpsudeo;
format long g
fminbndmax = [xmax2,yrealmax] ;
%Part D
[xzero,ypsuedozero]= fzero(@(t) h(t),20);
yrealzero = round(ypsuedozero);
ZERO = [xzero,yrealzero];
%Part B (height vs time)
figure;
plot(t,h(t),'blue',xmax2,yrealmax,'go','LineWidth',2);
hold on;
plot(xzero,yrealzero,'r.','MarkerSize',20);
title('Rocket Trajectory');
ylabel('altitude [m]');
xlabel('time [sec]');
axis([0 35 0 1500]);
legend('height','max','ground','location','ne')
I keep getting the
"Undefined operator '<' for input arguments of type 'function_handle'.
Error in height (line 7)
h(h<0) = 0;"
How would I resolve this? I got everything on my graph right, but I can't get the flat,horizontal line to appear at the very end.
  3 Kommentare
Ruten9
Ruten9 am 25 Okt. 2015
How would I go about that for this problem? I'm very lost.

Antworten (1)

Gareth Thomas
Gareth Thomas am 25 Okt. 2015
Try to remove: h(h<0) = 0;
From your height function. This will help you.
  2 Kommentare
Ruten9
Ruten9 am 25 Okt. 2015
My hw says that it should be there. I'm not sure why though.
Walter Roberson
Walter Roberson am 26 Okt. 2015
Then either your "hw" is wrong or you have misinterpreted your "hw" or you have implemented in a way that you are not intended to use.

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by