Azzera filtri
Azzera filtri

Create a function that is the sum of an arbitrary number of functions

1 visualizzazione (ultimi 30 giorni)
I would like to build a generate a Bezier function for a general number of Bezier points P using the equation:
ea46373831d9ae9adfa859cbcd305989980e6dc6
then
214de6a8893a07bb1ac8dbb731089f7f8f8cdaaa
I generate each term in the sum as a separate cell:
n=size(P,1)-1;
for i=0:n
Bi{i+1}=@(t) nchoosek(n,i)*(1-t).^(n-i).*t.^i*P(i+1,:)
end
this gives me a cell array of function handles.
Now I want to create the total Bezier function B(t) by adding all the terms Bi(t) but I am not sure how this is done in the best way.
Can someone give me a tip how to do this?
Thanks for answer in advance!

Risposte (1)

Walter Roberson
Walter Roberson il 18 Ott 2019
@(t) sum(cellfun(@(H) H(t), Bi))
  3 Commenti
Walter Roberson
Walter Roberson il 18 Ott 2019
What difficulty do you observe? I just tested it on some random data and it runs without error message.
Thomas Schäfer
Thomas Schäfer il 21 Ott 2019
Hi
Thank you for your time. Below I have pasted the MATAB scrit that I use to try this.
P=[[1:4]',[1:4]']*3+rand(4,2); %Four points, somewhat deviating from a straight line.
n=size(P,1)-1;
for i=0:n
Bi{i+1}=@(t) nchoosek(n,i)*(1-t).^(n-i).*t.^i*P(i+1,:);
end
B=@(t) sum(cellfun(@(H) H(t), Bi));
B(.5)
I get the following error:
Capture.PNG

Accedi per commentare.

Categorie

Scopri di più su Operating on Diagonal Matrices 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