Need Help Understanding Matlab Functions: Undefined Error

In summary, the conversation involves the speaker seeking help with a Matlab work related to calculating values for EA(x) and EP(x). They are having difficulties running the code and receiving an error message. The other person suggests trying a tutorial or switching to a different programming language.
  • #1
gfreeman
1
0
Hi,

I'm trying to help my sister with a Matlab work, but I'haven't work with MATLAB for a long time so I'm having some difficulties.

I'm trying to run this code but it gives me an error : Undefined function or method 'F' for input arguments of type 'double'. F(x)=(1-T)*F(x-1);

Code:
x=input('Number of years:');
D=input('loaned value:');
T=input('growing rate:');

F(0)=input('First year payment:');

K(0)=input('First year rate:');

EA(0)=D;
EP(0)=D;
for i=1:n
  F(x)=(1+T)*F(x-1);
  FA(x)=0.5*F(x);
  EA(x)=(EA(x-1)-FA(x))*(1+0.01);
  EP(x)=(EP(x-1)-F(x))-(1+K(x));
  K(x)=K(x-1)*EP(x)/EP(x-1);
end

the purpose of the work is calculate the value for EA(x) and EP(x).

thanks
 
Last edited:
Physics news on Phys.org
  • #2
This is not how you write Matlab scripts. While it is possible to define a function in Matlab, one primarily works on arrays (vectors and matrices) instead. Suggest you try one of their tutorials to get a feel for how to program Matlab, or switch to a different language like MathCAD.
 

FAQ: Need Help Understanding Matlab Functions: Undefined Error

1. What is a function in Matlab?

A function in Matlab is a set of instructions that can be called upon to perform a specific task. It takes in input variables, performs operations, and returns an output variable. Functions are useful for organizing code and making it more reusable.

2. How do I create a function in Matlab?

To create a function in Matlab, you can use the "function" keyword followed by the function name and input and output arguments in parentheses. Then, use the "end" keyword to close the function. For example:
function output = myFunction(input)
% function code
end

3. How do I call a function in Matlab?

To call a function in Matlab, you can simply type the function name followed by the input arguments in parentheses. For example:
myFunction(x, y)

4. Can I pass multiple outputs from a function in Matlab?

Yes, you can pass multiple outputs from a function in Matlab by using square brackets to enclose all the output variables within the function declaration. For example:
function [output1, output2] = myFunction(input)
% function code
end

5. How do I troubleshoot errors in a function in Matlab?

To troubleshoot errors in a function in Matlab, you can use the "dbstop" command to set a breakpoint in the function code. This will allow you to step through the code and see where the error is occurring. Additionally, you can use the "try-catch" statements to handle errors and display useful error messages.

Similar threads

Replies
1
Views
1K
Replies
8
Views
2K
Replies
6
Views
2K
Replies
2
Views
1K
Replies
18
Views
2K
Replies
3
Views
2K
Replies
8
Views
2K
Back
Top