How to construct piecewise polynomial?

2 次查看(过去 30 天)
I am using the following code to construct piecewise polynomial of a pascal matrix
clc
clear all
close all
% Read matrix
X=pascal(3);
disp(X);
[r c]=size(X);
i=2;
%while i==c
for j=1:c
z=X(i,j);
disp(z);
end
i=i+1;
%end
breaks=[0 4 10 15];
pp=mkpp(breaks,z);
Code is having error.

回答(1 个)

Anurag Ojha
Anurag Ojha 2024-6-13
Hi Avinash
The error in your code is occurring because the variable z is not defined outside the loop. To fix this, you can define z as an empty array before the loop and then append the values inside the loop.
Here's the corrected code:
clc
clear all
close all
% Read matrix
X = pascal(3);
disp(X);
1 1 1 1 2 3 1 3 6
[r, c] = size(X);
i = 2;
z = []; % Initialize z as an empty array
%while i==c
for j = 1:c
z = [z, X(i, j)]; % Append values to z
disp(z);
end
1 1 2 1 2 3
i = i + 1;
%end
breaks = [0 4 10 15];
pp = mkpp(breaks, z);
This code will construct a piecewise polynomial using the values of z obtained from the loop.

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by