Creating a polyval function
Ältere Kommentare anzeigen
Hi everybody, I'm actually trying to create a function wich would work like a polyval function but without any S and MU. Just with p and x : polyval(p,x). http://www.mathworks.com/help/matlab/ref/polyval.html But I have absolutely no idea how to do it... I know what i would have to do on a paper but no idea in MATLAB. For example, i don't know how to write this in MATLAB : y = p1*x^n + p2*x^n–1 + … + p*n^x + p*n+1 So if someone could just show me a tip or a way to find it... Thx :)
1 Kommentar
raviraja
am 13 Dez. 2013
Same Problem Here... Need Answer
Akzeptierte Antwort
Weitere Antworten (4)
Azzi Abdelmalek
am 13 Dez. 2013
Example
x=0:10
If you want to calculate a polynomial p=4x^2+2*x+5
p=[4 2 5]
out=polyval(p,x)
1 Kommentar
Patrick Allaglo
am 13 Dez. 2013
ledinh lam
am 27 Nov. 2016
Bearbeitet: ledinh lam
am 27 Nov. 2016
function p = poly_val(c0,c,x)
if isempty(c)==true
p =c0;
elseif isscalar(c)==true
p = c0+c*x;
else
w=c(:);
n=length(c);
a=x.^[1:n];
p=c0+a*w;
end
end
if true
% code
end
Jos (10584)
am 13 Dez. 2013
I do not really get your problem, but are you after something like this?
x = -5:5
p = [3 2 4]
y = p(1)
for k=2:numel(p),
y = y + p(k) * x.^(k-1) % you can change this to another formula f(k,p(k),x)
end
Patrick Allaglo
am 13 Dez. 2013
0 Stimmen
1 Kommentar
Simon
am 13 Dez. 2013
Make a table like
tt = -5:5;
Access your variable with index -3 like
V(tt==-3)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!