Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am struggling figuring out why my code is encountering these issues Consider the following systems of equations: y = - x 2 - A
I am struggling figuring out why my code is encountering these issues
Consider the following systems of equations:
where constants A and are parameters. Develope a function file that will solve for and given the values of the two parameters in the system using the NewtonRaphson iteration. Your function should accept the following inputs in order:
Ascalar value for
A scalar value for
A column vector of initial guesses for and
A stopping critierion for the iteration
Your function should return the following outputs in order:
A element column vector of the solutions and
The Jacobian matrix evaulated at the initial guesses and
The Euclidean norm for the residuals vector associated with the solution.
The number of iterations required for covergence with default maximum at
Note: Use an analytical formulation of the Jacobian matrix and do not rearrange the equations before computing partial derivatives if you want your code to pass the tests. You can use the referenced NRsysm in your solution code.
Function
function normres, iter Psolver es
Here is my current code:
function xy J normres, iter PsolverA B xi es
Initialize the Jacobian at current guess
J ones;
Jxi A;
J;
JxiBxi;
JBxi;
Define the system of equations
f @xyx Ax y;
g @xy x y Bxy;
maxiter ;
xold xi;
for iter :maxiter
Evaluate the function at current guess
Fval fxold xold; gxold xold;
Update the Jacobian at current guess
Jxold A;
J;
JxoldBxold;
JBxold;
Compute update step using NewtonRaphson method
deltax JFval;
Update estimate of root
xnew xold deltax;
Check convergence criterion Euclidean norm of residual vector
normres normFval;
if normres es allabsdeltax esabsxnew
break;
end
if iter maxiter && normres es
warningMaximum iterations reached without achieving desired tolerance.;
end
Update initial guess for next iteration
xold xnew;
end
xy xnew;
end
Here are my current errors:
Assessment: of Tests Passed
Does the initial Jacobian matrix have the correct values for the example function inputs? Pretest
Variable has an incorrect value.
Are the outputs correct for input values not given in the example?
Variable has an incorrect value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started