help with matlab error

조회 수: 18 (최근 30일)
Tony Vo
Tony Vo 2019년 4월 25일
편집: Cris LaPierre 2019년 5월 11일
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"
  댓글 수: 8
Tony Vo
Tony Vo 2019년 4월 25일
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 2019년 4월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2019년 5월 11일
편집: Cris LaPierre 2019년 5월 11일
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.

커뮤니티

더 많은 답변 보기:  원격 교육 커뮤니티

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by