Azzera filtri
Azzera filtri

How to construct piecewise polynomial?

2 visualizzazioni (ultimi 30 giorni)
Avinash Bhatt
Avinash Bhatt il 1 Mag 2019
Risposto: Anurag Ojha il 13 Giu 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.

Risposte (1)

Anurag Ojha
Anurag Ojha il 13 Giu 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.

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by