Clear Filters
Clear Filters

Projectile as a height handle, fzero used as a function of function to find hitting ground, syntax> fzero(function_handle, x_guess) guess by user hitting ground

2 views (last 30 days)
clc; clear all; close all;
% height_handle = @(t) height(t)
height_handle = @(t) -(9.8./2)*t^2+125*t+500
fplot(height_handle,[0,60])
x_guess=input('Enter a value when it will hit ground:')
% abs_height_handle=mod(height_handle) % tried abs(height_handle) does not
% work
function_handle=fzero(abs_height_handle,[0,60])
fzero(function_handle, x_guess)
ground=fzero(function_handle, 40)
% get the following errors
Error in Untitled2 (line 6)
abs_height_handle=mod(height_handle) % tried abs(height_handle) does not

Accepted Answer

Harsha Priya Daggubati
Harsha Priya Daggubati on 15 May 2020
Edited: Harsha Priya Daggubati on 15 May 2020
Hi,
It is advised to clearly explain your issue as text instead of title. Also leverage using code section to post your code. I assume your issue is in line 6. It is because the declared function handle height_handle, expects an input argument whenever a call is made. The following link might help you understand function handles better.
You can correct your call such that you pass an argument.
abs_height_handle= mod(height_handle(x_guess)) %I guess you should pass x_guess!
Also, mod expects two input arguments 'a' and 'm'. You can look into the following documentation link and figure out which method out of mod and abs to use.
Hope this solves your issue!

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!