# Trying to create polyval but mine only works for a single value of x , how to make it work for an array?

1 visualizzazione (ultimi 30 giorni)
Ali Ramadan il 9 Apr 2020
Modificato: Andrei Bobrov il 9 Apr 2020
i am trying to create polyavl but in deed i was only succssufull in creating a function that does polyval work in condition that x is a single value , how can i make my function work wetheir my x is a single value or an array?
my fonction that only works for a single value of x :
function [Y] = polyvalali(A,x)
Y = 0;
value = length(A) - 1;
p = value:-1:0;
for i = 1:value+1
Y = Y + A(i) * x^p(i);
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Andrei Bobrov il 9 Apr 2020
function Y = polyvalali(A,x)
Y = x(:) .^ (numel(A)-1:-1:0) * A(:);
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Argument Definitions in Help Center e File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!

Translated by