Filter löschen
Filter löschen

How to construct piecewise polynomial?

2 Ansichten (letzte 30 Tage)
Avinash Bhatt
Avinash Bhatt am 1 Mai 2019
Beantwortet: Anurag Ojha am 13 Jun. 2024
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.

Antworten (1)

Anurag Ojha
Anurag Ojha am 13 Jun. 2024
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.

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by