issue with fzero and root finding

8 vues (au cours des 30 derniers jours)
Amanda
Amanda le 3 Oct 2017
I am writing a function that computes the time that the rocket reaches some velocity. I am solving in using fzero. For my initial guess, I used 0. I know the domain for ln is 0, and infinity. I cannot make the domain until infinity, because the second bound needs to be finite. Do I need a second bound? I thought I could just have o, but I am not getting the correct output. Thank you.
% function tstar = fzero_rocket_example(u, g, q, m0, vstar)
%%Input
% m0: initial mass of rocket at time t=0
% g: gravitational constant
% q: fuel consumption rate
% u: velocity at which fuel expelled relative to rocket
% vstar: upward velocity value for which tstar is to be determined
%
%%Output
% tstar: the time that the rocket reaches the specified velocity, vstar. (scalar)
%%Write your code here.
%Compute time that the rocket reaches this velocity
tstar = 0; % Initial Guess
% fzero(function, x0) - used to designe the find the real root of a single equation
% function = name of function being evaluated
% x0 = initial guess
vstar = fzero(@(vstar)u*log(m0/(m0-q*tstar))-g*tstar,0)

Réponses (1)

Matt J
Matt J le 3 Oct 2017
You have a typo in your function
vstar = fzero(@(tstar), ...)

Catégories

En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by