How would I create a loop that ensures that all negative values of my function turn into zero?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
%% Problem 2
%Part A 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 -500 1500]); legend('height','max','ground','location','ne')
my height file (this was its own m-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(t) =0 end end
2 Comments
Image Analyst
on 26 Oct 2015
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!