필터 지우기
필터 지우기

Should the max function and the fminbnd function produce the same result? Also, is there something wrong with my MATLAB syntax?

조회 수: 1 (최근 30일)
this is my code guys. my height.m file is: function [h] = height(t)
h = @(t) ((-9.8).*(2.^(-1))).*(t.^2) + 125.*t + 500;
%h(h<0) = 0; %I DON'T UNDERSTAND WHY THIS DOESN'T WORK. if h(t) <0 h=0 end end
My actual program is: %Part A clear all; clc; t = 0:.01:30; h = height(t); %the h(h<0) is acting weird
%Part C (maxima)---I swapped the order for the plotting %max function [xpsudeomax,ymax] = max(h(t)); xrealmax = t(ymax); maxfunction = [xrealmax,ymax] %THIS IS LESS ACCURATE THAN THE BELOW VERSION-WHY?
%fminbnd function [xmax2,ymaxpsudeo]= fminbnd(@(t) (-1.*h(t)),0,30); yrealmax = -1.*ymaxpsudeo; format long g fminbndmax = [xmax2,yrealmax] %Is fminbnd and max function suppposed to give the %exact same answer? %THIS IS THE ACCURATE ONE-WHY?

채택된 답변

John D'Errico
John D'Errico 2015년 10월 23일
NO. max is not an optimization tool. It just finds the maximum element of an array. VERY different.
Anyway, fminbnd is a MINIMIZER.
Finally, as you have written it, h is a function handle. You cannot then do a vectorized array operation on it, like this:
h(h<0) = 0;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by