? Undefined function or method 'strike' for input arguments of type 'double'

In summary: In short, in MATLAB, if you want to pass more than one input as an argument to a function, you need to use the varargin command. For example, you could write varargin(2, 'x');This would pass the first two arguments (x and y) to the function.
  • #1
elisamars
3
0
? Undefined function or method 'strike' for input arguments of type 'double'

Hi all..I have some problem with a Matlab script..
The aim of my exercise is to plot the change of a derivative's price (a swaption) on the basis of the change of its principal parameters (for example the strike).
This is the script:

strike=0.1:0.01:1.5
for i=1:lenght(strike)
swaption_strike(i)=swaption_price(strike(i))
end

where the function swaption_price is defined into another script and includes of course other variables.

It turns out this error message:

swaption_price(strike(i))
? Undefined function or method 'strike' for input arguments of type 'double'.

What could be wrong?

Thanks

Elisa
 
Physics news on Phys.org
  • #2


From the error message it sounds as if somehow i becomes a non-integer value and it tries to index strike, which MATLAB is interpreting as a function call. How do you define the swaption_price() function?

Additionally, it is always preferable to vectorize functions in MATLAB rather than use a for loop. If you use element by element operations in the function, you can just call:
Code:
strike=0.1:0.01:1.5;
swaption_strike = swaption_price(strike);
instead of
Code:
strike=0.1:0.01:1.5;
[COLOR="Blue"]for[/COLOR] i=1:length(strike);
    swaption_strike(i) = swaption_price(strike(i));
[COLOR="Blue"]end[/COLOR]

This is more efficient in MATLAB.
 
Last edited:
  • #3


You're right, it is better to avoid the use of loops...
anyway I have solved the problem..I had to include in my script all the swaption_price function's variables evaluated in a point, with just the strike as indexed parameter!
 
  • #4


Ok I've solved my problem..now I want to parametrize on a variable which is NOT an input argument of my original function..After a quick look on the web, I found the command varargin...Some idea??

Thanks!

Elisa
 
  • #5


varargin means you have variable amount of arguments in. It's a way to say "if there two inputs do this, if three, then this" etc.

Not sure what you're asking tho. If you restate your question at the more lower level mechanics (I'm a "left" "right" kinda guy) I'll try and help you out
 

1. What does the error "Undefined function or method 'strike' for input arguments of type 'double'" mean?

This error means that the function or method 'strike' has not been defined or declared in the code, and therefore cannot be executed with the given input arguments of type 'double'.

2. Why am I getting the error "Undefined function or method 'strike' for input arguments of type 'double'"?

You are getting this error because the function or method 'strike' has not been properly defined or declared in the code. This can happen if the function is misspelled, not included in the code, or if there are issues with the input arguments being passed to the function.

3. How can I fix the error "Undefined function or method 'strike' for input arguments of type 'double'"?

To fix this error, you will need to properly define or declare the function or method 'strike' in your code. Make sure it is spelled correctly and that all necessary input arguments are included and correctly formatted.

4. Can I use the 'strike' function with input arguments of other types?

Yes, the 'strike' function can be used with input arguments of other types as long as it has been properly defined or declared in the code to accept those types of inputs.

5. Is there a way to check if the 'strike' function has been defined or declared in the code?

Yes, you can use the built-in function 'exist' to check if the 'strike' function exists in the code. If it returns a value of 1, then the function has been defined or declared. Otherwise, it will return a value of 0.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
17K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top