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

Click For Summary

Discussion Overview

The discussion revolves around a MATLAB scripting issue related to an undefined function error encountered while attempting to plot the price of a swaption based on varying strike values. Participants explore the nature of the error, propose solutions, and discuss function parameterization.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Elisa describes an error message indicating that MATLAB cannot find the function 'strike' when attempting to index it, suggesting a potential issue with the variable 'i' becoming a non-integer.
  • One participant suggests that vectorizing the function call is preferable to using a for loop, proposing an alternative method to call the function swaption_price directly with the entire array of strike values.
  • Elisa mentions resolving the initial problem by ensuring all necessary variables for the swaption_price function are included in the script, with strike as the indexed parameter.
  • Elisa expresses a desire to parametrize a variable that is not an input argument of the original function and inquires about the use of varargin.
  • Another participant explains that varargin allows for a variable number of input arguments and suggests restating the question for clarity.

Areas of Agreement / Disagreement

Participants generally agree on the benefits of avoiding loops in MATLAB and the utility of vectorization. However, there is no consensus on the best approach to implement the desired parameterization using varargin, as the discussion remains open-ended.

Contextual Notes

There is a mention of a potential misunderstanding regarding the indexing of the strike variable and the need for clarity on the mechanics of using varargin. The discussion does not resolve these points fully.

Who May Find This Useful

This discussion may be useful for MATLAB users encountering similar scripting issues, particularly those related to function definitions, parameterization, and error handling in programming.

elisamars
Messages
3
Reaction score
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


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;
for i=1:length(strike);
    swaption_strike(i) = swaption_price(strike(i));
end

This is more efficient in MATLAB.
 
Last edited:


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!
 


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
 


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
 

Similar threads

Replies
1
Views
18K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
148K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
4K