I need to perform element by element subtractions within a matrix.
1 次查看(过去 30 天)
显示 更早的评论
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
回答(1 个)
Image Analyst
2022-9-27
编辑:Image Analyst
2022-9-27
5 个评论
Steven Lord
2022-9-28
编辑:Steven Lord
2022-9-28
It's one of the building blocks you need.
x = (1:5).^2
y = diff(x)
check = [y(3), x(4)-x(3)] % should match
Read carefully through the diff documentation page, paying specific attention to the "Approximate Derivatives with diff" example and the description of the dim input argument.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!