Two basic MATLAB problems help

Hi, I'm a student studying engineering and I have my first exam tomorrow on MatLab. I'm going through some practice problems and ran into two that I don't understand, I posted them below and was wondering if anyone could help me out! Thanks
6) Assume that the function *diff* does not exist. Write your own expression(s) to accomplish the same thing for a vector.
7) Find expressions that will evaluate the function f of two variables x and y:
f(x,y) = 3*x - y
where x ranges from 1 to 2 and y ranges from 1 to 5.

댓글 수: 3

Cedric
Cedric 2013년 9월 27일
편집: Cedric 2013년 9월 27일
For 6, build an numerical example, e.g. with a vector
x = [4, 1, 7, 9]
if you understand what DIFF does, it is easy to emulate it with a simple loop (hint: it doesn't start on the first element).
For 7, you can certainly build two nested loops over elements of x and y and build an array of solutions, but you could also consider an approach where X and Y are appropriate arrays of values of x and y, and perform the evaluation of f in one matrix equation. Look at the doc of MESHGRID to understand this comment.
Walter Roberson
Walter Roberson 2013년 9월 27일
편집: Walter Roberson 2013년 9월 27일
#6, diff() can be done without any loop.
#7 can be done without any loop and without any meshgrid (or ndgrid. or repmat)
Jan
Jan 2013년 9월 27일
편집: Jan 2013년 9월 27일
These problems are not complicated. So I wish you good luck for your first exam tomorrow.

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

답변 (2개)

Image Analyst
Image Analyst 2013년 9월 27일

1 개 추천

Hint: type out vec(1:end-1) and vec(2:end) and see what that shows.
Jan
Jan 2013년 9월 27일

0 개 추천

#7: When x ranges from 1 to 2 only, you can write down the equation for x=1 and x=2 manually. If you define y=1:5, the work is done already.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2013년 9월 26일

답변:

Jan
2013년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by