MATLAB Answers

How can I plot a function i can´t define before calculating it?

1 view (last 30 days)
Jose Ramirez
Jose Ramirez on 19 Oct 2020
Commented: Jose Ramirez on 19 Oct 2020
X = [1,2,4,5, 17, 34];
Y = [8,14,25,1,-3,27];
syms x;
sum = 0;
for i = 1: length(X)
u = 1;
l = 1;
for j = 1: length(X)
if j ~= i
u = u * (x - X(j));
l = l * (X(i)-X(j));
end
end
sum = sum + ((u/l)*Y(i));
end
disp(simplify(sum));
fplot(sum(x));
I´m trying to use Lagrange´s method for finding a polynomial, but after finding it i can´t plot the function "sum".
Is there a way to do that?

  0 Comments

Sign in to comment.

Accepted Answer

David Hill
David Hill on 19 Oct 2020
fplot(sum);

  1 Comment

Jose Ramirez
Jose Ramirez on 19 Oct 2020
Thanks! I had tried it but didn´t notice until now that the issue is actually the scale, it somehow seems off.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by