Info

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

How can I deal with function handle errors? I need the graph to produce a flat line after it touches the horizontal axis.

1 Ansicht (letzte 30 Tage)
%Part A
clear all; clc;
t = 0:.01:35;
h = height(t)
%Part C (maxima)---I swapped the order for the plotting
%max function
[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 --- awkward position was for plotting
[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);
ylabel('altitude [m]');
xlabel('time [sec]');
title('Rocket Trajectory');
legend('height','max','ground','location','ne')
axis([0 35 0 1500]);
%%Corresponding 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
% h=0
%end
% end

Antworten (1)

Walter Roberson
Walter Roberson am 25 Okt. 2015
h = @(t) max(0,the current expression)

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