Matlab help User defined function

  • Thread starter Thread starter qiyan31
  • Start date Start date
  • Tags Tags
    Function Matlab
AI Thread Summary
The user-defined function for calculating height in MATLAB appears correctly defined, but the error arises from how it is being called. The function `fminbnd` requires a single-variable function, while the user is trying to pass multiple parameters. To resolve the issue, the user should call the `Height` function with specific values for `t`, `V`, and `Theta` directly in the command window. For example, using `Height(3, 4, 60)` would work correctly. The problem lies in the function call rather than the function definition itself.
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.
 

Similar threads

Replies
3
Views
1K
Replies
1
Views
2K
Replies
1
Views
2K
Replies
0
Views
1K
Back
Top