Matlab help User defined function

  • Thread starter Thread starter qiyan31
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a user-defined function in Matlab, specifically addressing an error related to undefined input arguments. Participants explore the correct usage of the function and its integration with Matlab's optimization function, fminbnd.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant presents a user-defined function and reports an error regarding an undefined input argument "V".
  • Another participant suggests that the function definition appears reasonable and requests clarification on how the function is being called.
  • A participant provides an example of calling the function using fminbnd, indicating that the issue may lie in the function's usage rather than its definition.
  • Another reply emphasizes that the fminbnd function requires a single-variable function, implying that the current usage may not align with this requirement.
  • One participant notes that the error arises when the function is executed without providing values for all input arguments.

Areas of Agreement / Disagreement

Participants generally agree that the function definition is likely correct, but there is disagreement on the proper way to call the function and integrate it with fminbnd. The discussion remains unresolved regarding the optimal approach to using the function.

Contextual Notes

There are limitations regarding the assumptions made about the function's inputs and the specific requirements of fminbnd. The discussion does not resolve these issues.

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 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K