Question

Solve the following equations graphically and numerically using roots function on matlab a) x ^ 5...

Solve the following equations graphically and numerically using roots function on matlab

a) x ^ 5 - 3x ^ 3 + 2x ^ 2 - 1 = 0
b) exp(exp(-x)) -5 x^2=0

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

clc
clear
close all

f1 = @(x) x.^5 - 3.*x.^3 + 2.*x.^2 - 1;
f2 = @(x) exp(exp(-x)) - 5.*x.^2;

%% numerical method with roots() function
% on f1
c = [1 0 -3 2 0 -1]; %coefficients
r = roots(c); % all complex and real roots

% getting real roots for f1
j=1;
for i=1:numel(r)
if imag(r(i))==0
real_roots(j) = real(r(i));
j = j+1;
end
end

roots_f1 = real_roots
%% f2
x2 = linspace(-2,1,100);
ff2 = f2(x2);
pos = find(ff2>=0);
neg = find(ff2<=0);
root_id_f2 = ceil((pos(end)+neg(1))/2);
roots_f2 = x2(root_id_f2)

%% graphical method

% with f1
figure
x1 = linspace(-2,2,100);
plot(x1,f1(x1)) % plot f1(x)
hold on
plot(roots_f1,f1(roots_f1),'o r') % show roots
xlabel('x')
ylabel('f(x)')
legend('f(x)','roots','location','best')
title('f(x) = x^5 - 3*x^3 + 2*x^2 - 1')
grid on

% with f2
figure
plot(x2,f2(x2)) % plot f2(x)
hold on
plot(roots_f2,f1(roots_f2),'o r') % show roots
xlabel('x')
ylabel('f(x)')
legend('f(x)','roots','location','best')
title('f(x) = exp(exp(-x)) - 5*x^2')
grid on

%-----------------------------------------------------------------------

----------------------------------------------------------------------------------------


------------------------------------------------------------------------------
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
Solve the following equations graphically and numerically using roots function on matlab a) x ^ 5...
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