loops to define a matrix

조회 수: 2 (최근 30일)
Morley
Morley 2011년 10월 7일
having trouble with this problem. i understand how loops and conditional statements work, but i think im just having trouble seeing where to begin and what to assign varibles to acheive the outcome.
help greatly appreciated!!
use loops to create a 4X3 matrix in which the value of each element is the sum of its row number and its column number divided by the square of its column number. for example, the value of element (2,3) is (2+3)/3^2 = 0.555
help please!! thanks
  댓글 수: 1
the cyclist
the cyclist 2011년 10월 7일
Here is a hint on how to begin: Break the problem in parts:
First, write the loops you need (one loop for rows, and another for columns), without doing any calculations at all.
Then, define variable for the intermediate values you need (e.g. the sum).
Then, put those pieces together.
This is a fairly simple MATLAB problem. You might want to read the "Getting Started" guide, and possibly tell your teacher that you are struggling to even get started. Don't fool yourself into thinking that you really understand; it is simple problems like these that BUIILD your understanding.

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

답변 (1개)

Sean de Wolski
Sean de Wolski 2011년 10월 7일
bsxfun(@(x,y)(x+y)./(y.^2),(1:4).',1:3)
"Look Ma, No loops!" ~ Walter Roberson

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by