Effacer les filtres
Effacer les filtres

How to construct piecewise polynomial?

2 vues (au cours des 30 derniers jours)
Avinash Bhatt
Avinash Bhatt le 1 Mai 2019
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.

Réponses (1)

Anurag Ojha
Anurag Ojha le 13 Juin 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.

Catégories

En savoir plus sur Polynomials dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by