Question

OUTO OP Use a numerical method of your choice to solve for x in the following equation. Stop when εa < 0.1%. Choose your init

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Script:

close all
clear
clc

syms x
f = 4*cos(x) - exp(x);
tol = 0.1e-2; % 0.1%
x0 = 1; % Initial guess
x = newton(f, x0, tol);
fprintf('Solution, x = %.4f\n', x)

function x = newton(f, x0, tol)
x = x0;
df = diff(f); % f'(x)
while true
x_ = x; % Save previous iteration's result
x = double(x - subs(f, x)/subs(df, x)); % Newton Update Rule
if abs(x_ - x) <= tol % Stopping criteria
break;
end
end
end

Output:

Solution, x = 0.9048

Add a comment
Know the answer?
Add Answer to:
OUTO OP Use a numerical method of your choice to solve for x in the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT