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

1 回表示 (過去 30 日間)
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

採用された回答

Harsha Priya Daggubati
Harsha Priya Daggubati 2020 年 5 月 15 日
編集済み: Harsha Priya Daggubati 2020 年 5 月 15 日
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!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by