Borrar filtros
Borrar filtros

How to construct piecewise polynomial?

2 visualizaciones (últimos 30 días)
Avinash Bhatt
Avinash Bhatt el 1 de Mayo de 2019
Respondida: Anurag Ojha el 13 de Jun. de 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.

Respuestas (1)

Anurag Ojha
Anurag Ojha el 13 de Jun. de 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.

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by