Effacer les filtres
Effacer les filtres

how to minus a sequence value

1 vue (au cours des 30 derniers jours)
Noriham B
Noriham B le 13 Sep 2022
Modifié(e) : Rik le 13 Sep 2022
a=-4;
b=4;
x=a:1:b;
y=x.^2-4.*x;
from the above code, i will have value y= 32,21,12,5,0,-3,-4,-3,0
then, what i do do next is to find the difference between answer
ex:
abs|21-32|=11
abs|12-21|=9
abs|5-12|=7
and so on

Réponse acceptée

Rik
Rik le 13 Sep 2022
The diff function will do what you want. You can use abs to get the absolute value.
  2 commentaires
Noriham B
Noriham B le 13 Sep 2022
Modifié(e) : Rik le 13 Sep 2022
tq...I really appreciate it...I am juz new to Matlab, learning from the internet
I have tried just now
to obtain the value 11,9 7.......and so on
just type
diff(y,1,2);
or diff(y);
both worked
but, what if I want to add, multiply and do other operations, is it possible sir?
let say now I want to do multiplication?
abs|21*32|=11
abs|12*21|=9
abs|5*12|=7
and so on
Rik
Rik le 13 Sep 2022
That is possible with indexing:
a=-4;
b=4;
x=a:1:b;
y=x.^2-4.*x;
mulitplied_values= y(1:(end-1)).*y(2:end);
result=abs(mulitplied_values);
disp(result)
672 252 60 0 0 12 12 0

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by