Hi, I'm new
Show older comments
How can I solve a cubic equation using method of Taylor in MATLAB? for example this one: x^3+x^2-16*x=16. please, help me :) if you already have the similar task please send me or attach file. thanks
2 Comments
Azzi Abdelmalek
on 22 May 2016
Hi, I'm new, can't be a title to your question
Answers (2)
Image Analyst
on 22 May 2016
Try using fzero() like this, all in an m-file called test3.m. It correctly gives a root of -1:
function test3
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Plot the data
% Make 400 points along the x axis from -3 to +3.
x = linspace(-3, 3, 400);
yValues = x.^3 + x .^ 2 - 16 * x;
% Plot the function.
plot(x, yValues, 'b-', 'LineWidth', 2);
grid on;
title('y = x.^3 + x .^ 2 - 16 * x', 'FontSize', fontSize);
% Plot a line along the x and y axes.
hold on;
line(xlim, [0, 0], 'Color', 'k', 'LineWidth', 2); % Plot x axis.
line([0, 0], ylim, 'Color', 'k', 'LineWidth', 2); % Plot y axis.
% Plot a line at y = +16
line(xlim, [16, 16], 'Color', 'b', 'LineWidth', 2);
x0 = -2; % initial point
theRoot = fzero(@f, x0)
function y = f(x)
y = x.^3 + x .^ 2 - 16 * x - 16; % Subtract 16 so the function is zero at the root.

%
7 Comments
kvk lord
on 22 May 2016
Image Analyst
on 22 May 2016
I don't know what "The Method of Taylor" is. What is it? Who was he?
kvk lord
on 22 May 2016
Image Analyst
on 22 May 2016
No I don't. Did you see my last comment? All I've heard of is the "Taylor Series", which doesn't seem related to this at all. Again, I don't know what "The Method of Taylor" is. What is it? Who was he?
kvk lord
on 22 May 2016
kvk lord
on 22 May 2016
kvk lord
on 22 May 2016
Roger Stafford
on 22 May 2016
It’s a lot easier to do this one by hand and bypass matlab altogether:
x^3+x^2-16*x-16 = (x-4)*(x+4)*(x+1) = 0
which gives you its three possible solutions immediately: 4, -4, and -1. However, if you are determined to have the computer do it, use ‘roots’:
r = roots([1,1,-16,-16]);
1 Comment
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
