How can i evaluate the 2nd equation in this program? I tried some and it doesnt show the value

1 view (last 30 days)
Here i got the 3 equations but i want to evaluate the equations with values of x , what code should i add?
For example in the 2nd eqauation i want to evaluate it when x=5.333
%% Quadratic Spline Method
x = [0 5 7 8 10];
y = [0 2 -1 -2 20];
syms a1 a2 a3 b1 b2 b3 c1 c2 c3 x1 x2 x3 x4 x5 x6 x7 x8
a1 = 0;
x1 = a1*x(2)^2+b1*x(2)+c1 == y(2);
x2 = a2*x(2)^2+b2*x(2)+c2 == y(2);
x3 = a2*x(3)^2+b2*x(3)+c2 == y(3);
x4 = a3*x(3)^2+b3*x(3)+c3 == y(3);
x5 = 2*a2*x(2)+b2 == 2*a1*x(2)+b1;
x6 = 2*a3*x(3)+b3 == 2*a2*x(3)+b2;
x7 = a1*x(1)^2+b1*x(1)+c1 == y(1);
x8 = a3*x(4)^2+b3*x(4)+c3 == y(4);
m1 = [0 x(2) 1;0 x(1) 1 ];
s1 = [y(2) y(1)]';
d1 = m1\s1;
a1 = d1(1);
b1 = d1(2);
c1 = d1(3);
m2 = [2*x(2) 1 0; x(2)^2 x(2) 1; x(3)^2 x(3) 1];
s2 = [2*a1*x(2)+b1 y(2) y(3)]';
d2 = m2\s2;
a2 = d2(1);
b2 = d2(2);
c2 = d2(3);
m3 = [x(3)^2 x(3) 1;x(4)^2 x(4) 1; 2*x(3) 1 0];
s3 = [y(3) y(4) 2*a2*x(3)+b2]';
d3 = m3\s3;
a3 = d3(1);
b3 = d3(2);
c3 = d3(3);
syms x
disp("equation for the first sub-interval is");
e1 = a1*x^2+b1*x+c1 == 0;
disp(e1);
disp("equation for the second sub-interval is");
e2 = a2*x^2+b2*x+c2 == 0;
disp(e2);
disp("equation for the third sub-interval is");
e3 = a3*x^2+b3*x+c3 == 0;
disp(e3);
  3 Comments
Miku
Miku on 10 Aug 2022
the (e2) sir ,2nd sub interval
(99*x)/10 - (19*x^2)/20 - 95/4 == 0 , i want to evaluate this without creating new script

Sign in to comment.

Answers (0)

Categories

Find more on Interpolation 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!