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

조회 수: 1 (최근 30일)
Sean Flanagan
Sean Flanagan 2022년 9월 27일
편집: Steven Lord 2022년 9월 28일
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
Sean Flanagan
Sean Flanagan 2022년 9월 28일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2022년 9월 27일
편집: Image Analyst 2022년 9월 27일
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.
  댓글 수: 5
Steven Lord
Steven Lord 2022년 9월 28일
편집: Steven Lord 2022년 9월 28일
It's one of the building blocks you need.
x = (1:5).^2
x = 1×5
1 4 9 16 25
y = diff(x)
y = 1×4
3 5 7 9
check = [y(3), x(4)-x(3)] % should match
check = 1×2
7 7
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.
Sean Flanagan
Sean Flanagan 2022년 9월 28일
Thanks for the help mate. Its really apreciated.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by