## help with matlab error

### Tony Vo (view profile)

on 25 Apr 2019
Latest activity Edited by Cris LaPierre

### Cris LaPierre (view profile)

on 11 May 2019
Just need help with the problem
1st part of code is in the attahcment and heres the second part
I am getting an error that says "variable reshas an incorrect value" and "output arguement xroot and maybe others not assigned to during call to PA_secant" and "not enough output arguements"

Tony Vo

### Tony Vo (view profile)

on 25 Apr 2019
used for the first three tests
f = @(x) sin(2*x) - tan(x/4);
[xr,res,ea,iter] = PA3_secant(f, [1 1.1], 1e-3, 50);
Tony Vo

### Tony Vo (view profile)

on 25 Apr 2019
this is the problem statement
Write a function m-file that implements the secant method. Your function should accept the following inputs (in order):
1. A function defining the roots problem
2. A vector of two initial guesses (first element is the first guess, second element is second guess)
3. A stopping criterion ( es ) for the numerical solution with a default value of 1e-5
4. A maximum iteration count for the numerical solution with a default value of 30
5. An arbitrary number of parameter values associated with the roots problem
Your function should output the following four scalar outputs (in order):
1. The root estimate
2. The residual in the numerical solution
3. The approximate relative error in the numerical solution
4. The number of iterations required for convergence
Walter Roberson

### Walter Roberson (view profile)

on 25 Apr 2019
When I run your code with those parameters, I do not get any error message.
"Variable res has an incorrect value" looks like it might be from the automatic grading system.

### Cris LaPierre (view profile)

on 11 May 2019
Edited by Cris LaPierre

### Cris LaPierre (view profile)

on 11 May 2019

It looks like your teacher is using MATLAB Grader for this problem. Because of variable scope in a function, MATLAB Grader is calling your function with inputs your teacher defines, and assessing the outputs. It can not check any other variables. The outputs are captured in variables your teacher has named, which is why you see an error message about a variable your code does not create.
It would appear the output variable they named res is not being assigned the expected value by your function. The inference, then, is that your function has not been properly implemented.
I think it's safe to assume res = residual. Check how you are calculating your residual. Compare to your notes from class. If there is any feedback provided in this assessment test, use that to help find your mistake.