fsolve usage

I would like to find help fixing my m-file and command windows. M-File that will determine the V0(initial velocity) and t(detonation time) necessary to hit a target.
input data: theta
weight %Weight of projectile
c %Aerodynamic drag coefficient
return data: V0, t
function [V0,t]=offensive(theta,weight,c)
g=32.2;
weight=10;
theta=pi/6;
t=sqrt((2/g)*(300+5000*tan(theta)));
V0=[5000/(t*cos(theta))];
[V0,t]
command window
[V0,t]=fsolve(offensive,pi/6,10,0.1)
ans = 410.3725 14.0689
??? Error using ==> fsolve
FUN must be a function name, valid string expression,
or inline function object.
Thanks.

답변 (2개)

Walter Roberson
Walter Roberson 2011년 10월 16일

0 개 추천

[V0,t]=fsolve(@offensive,pi/6,10,0.1)
With the code you had, you were invoking the routine named "offensive" with no arguments, and passing the (numeric) result of that routine in as the first argument to fsolve.
Note that you will need to rewrite your routine "offensive" to use the parameters passed in to it instead of overwriting them in the routine.

댓글 수: 2

Nathanael
Nathanael 2011년 10월 17일
How do you use fsolve? do you have to put @ on front. or it just indicating it is the function's name?.
When I am using what you wrote it gave me an error.
??? [V0,t]=fsolve(@
|
Missing variable or function.
Walter Roberson
Walter Roberson 2011년 10월 17일
How old is your MATLAB version? Anonymous functions were not supported in MATLAB 5 or some of MATLAB 6. You might have to code as
[V0,t] = fsolve('offensive',pi/6,10,0.1)

댓글을 달려면 로그인하십시오.

Naz
Naz 2011년 10월 16일

0 개 추천

command line:
[Vo,t]=offensive(pi/6,10,.1)
Your function code does not make sense. You pass theta, weight, c to it, but then you rewrite 'weight' and 'theta' again inside the function. Then, I dont see you using these parameters - nor 'c', not 'weight' to calculate the V0 and t.
You are getting the answer because you did not comment the last line in the function code. Also, I dont think you need that line at all.

댓글 수: 4

Naz
Naz 2011년 10월 16일
Is it necessary to use fslove?
Walter Roberson
Walter Roberson 2011년 10월 16일
If you are going to ignore the drag coefficient (as you do in your code) then there is no need to use fsolve: the equation can be solved analytically, such as is described at http://en.wikipedia.org/wiki/SUVAT_equations#Examples
My understanding is that once you introduce drag, you are solving a differential equation. You would not generally use fsolve() for differential equations, but perhaps this particular one can be done that way.
Nathanael
Nathanael 2011년 10월 17일
The problem states that I have use fsolve command.
Walter Roberson
Walter Roberson 2011년 10월 17일
If you show the calculation with drag included, I would have a better chance of analyzing the situation.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

태그

질문:

2011년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by