Matlab help! User defined function!

  • Thread starter qiyan31
  • Start date
  • #1
3
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 plz
 

Answers and Replies

  • #2
33,744
5,433
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 plz
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.
 
  • #3
3
0
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);
 
  • #4
33,744
5,433
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.
 
  • #5
78
0
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
 
  • #6
uart
Science Advisor
2,776
9
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.
 

Related Threads on Matlab help! User defined function!

  • Last Post
Replies
8
Views
6K
  • Last Post
Replies
3
Views
2K
Replies
3
Views
3K
Replies
2
Views
1K
Replies
1
Views
2K
Replies
11
Views
1K
Replies
1
Views
4K
Replies
25
Views
4K
  • Last Post
Replies
16
Views
3K
Top