0

I've created this small program just for simplicity of the question, I am having some trouble using my function inside a while loop

this is the script;

x = 1;
y = 1;
while x<10
    y = func(x,y);
    x = x + 1;

this is the function, func;

function [] = func(x,y)

y- exp(-x)

end

I get the error of

Error using func
Too many output arguments.

what am I doing wrong

1 Answer 1

2

When you declare the function:

function [] = func(x,y)

You have specified that there will be no return values, yet when you call it you require a return value:

y = func(x,y);

To fix this issue you must alter your function declaration, e.g.:

function y_out = func(x,y)

Also, within your function declaration you have y- exp(-x), which will not change the value of y; did you intend to have y=exp(-x)?

Sign up to request clarification or add additional context in comments.

2 Comments

I want it to be f(x,y) = y - exp(-x), and return the value of f(x,y)
In which case the line should be y_out = y - exp(-x);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.