Matlab help User defined function

  • Thread starter Thread starter qiyan31
  • Start date Start date
  • Tags Tags
    Function Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 3K views
qiyan31
Messages
3
Reaction score
0
I tried to make a user-defined function.
function Ht=Height(t,V,Theta);
Ht=V*t*sin(Theta)-4.9*t.^2;

but then i kept on getting Input argument "V" is undefined...

can someone help me please
 
Physics news on Phys.org
qiyan31 said:
I tried to make a user-defined function.
function Ht=Height(t,V,Theta);
Ht=V*t*sin(Theta)-4.9*t.^2;

but then i kept on getting Input argument "V" is undefined...

can someone help me please
What you show above seems reasonable for the function definition. Show us how you are calling this function - that might be what's causing your error.
 
Mark44 said:
What you show above seems reasonable for the function definition. Show us how you are calling this function - that might be what's causing your error.

Here's the function.

Ht=fminbnd(@Height,0,5000,V,Theta);
 
qiyan31 said:
Here's the function.

Ht=fminbnd(@Height,0,5000,V,Theta);
This doesn't make any sense to me. Use the function you wrote (the Height function) to calculate height, and then pass the value returned by that function as the first parameter in your fminbnd function.
 
You get that error when you try to run the function without giving it values for the arguments that you are passing into the function.

If you go to matlab's command window type the function's name and then the values that you want to use. For example:

Height(3, 4, 60)
t = 3, V = 4, theta = 60
 
The problem is not the function, but the way you are trying to use it.

The function fminbnd() expects to be passed a function of a single variable.