Indexing errors on sum
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
In = [38.68 7.84 5.14 3.92 3.14 2.62 2.22 1.78 1.74 1.55];
X = [1.4875 -0.4216 0.0390 -0.0008]
for c = 1:length(In)
Yf = @(In)sum(X(1:end).*In(c).^(0:Order));
Y(c) = Yf(c)
end
plot(In,Y)
This gives me the error Index exceeds the number of array elements (1).
the code is supposed to take the length of X(a list of coeficients) and plots the function
Y = X(1)*In.^(0) + X(2)*In.^(1) + X(3)*In.^(2) + X(4)*In.^(3)
So if the length of X is 5, then the function should be
Y = X(1)*In.^(0) + X(2)*In.^(1) + X(3)*In.^(2) + X(4)*In.^(3) + X(5)*In.^(4)
Am I doing this wrong? Is it possible to have matlab build the function itself like this?
0 Commenti
Risposta accettata
Steven Lord
il 30 Set 2020
I'm guessing you've defined a variable named sum that's preventing you from calling the sum function. If my guess is correct clear the variable and recreate the anonymous functions.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus 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!