# I need to perform element by element subtractions within a matrix.

1 view (last 30 days)
Sean Flanagan on 27 Sep 2022
Edited: Steven Lord on 28 Sep 2022
I have a 21x2 matrix for a given row say row 12, I need to calculate the errors by using the following numerical schemes; backwards - ((y(12)-y(11)/x(12)-x(11)), forwards - (y(13)-y(12))/(x(13)-x(12), and central (y(13)-y(11))/(x(12)-x(11)). My program needs to use matrix based calculations to solve for each element of the matrix. The following code works for the forward but I cant get the backwards or central working.
yn1 =y(2:length(y));
yn = y(1:length(y)-1);
xn1 =x(2:length(x));
xn = x(1:length(x)-1);
Thanks for the help
##### 2 CommentsShowHide 1 older comment
Sean Flanagan on 28 Sep 2022
This is the series of equations I need to satisfy. The matlab script that I have posted solves the forward equation. But I am stuck on the backwards and central equation.

Image Analyst on 27 Sep 2022
Edited: Image Analyst on 27 Sep 2022
Not sure what you mean by the 11, 12, and 13, but why not use the built in diff, conv, and, if you have to flip?
Give an short actual numerical example (inputs and outputs) if you still need help.
Sean Flanagan on 28 Sep 2022
Thanks for the help mate. Its really apreciated.

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!