필터 지우기
필터 지우기

How to define following function?

조회 수: 1 (최근 30일)
Ajay Goyal
Ajay Goyal 2017년 2월 6일
댓글: the cyclist 2017년 2월 6일
I have two row vectors (say A1(1:5) and B1(1:5)). I wish to define a function 'a(t)' as given below. I am repeatedly getting error "Matrix dimensions must agree.". Can anyone help?
a=@(t) A1.*cos(B1*t) For ease: A=[1 2 3 4 5]; B=[9 1 2 6 4]
  댓글 수: 1
the cyclist
the cyclist 2017년 2월 6일
This code works just fine for me.
A1=[1 2 3 4 5];
B1=[9 1 2 6 4];
a = @(t) A1.*cos(B1*t);
What are you trying to do next? Can you post the code that actually gives the error?

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

답변 (1개)

Star Strider
Star Strider 2017년 2월 6일
Try something like this:
A = [1 2 3 4 5];
B = [9 1 2 6 4];
[A1,B1] = meshgrid(A,B);
a = @(t) A1.*cos(B1.*t);
The function works for single values of ‘t’. You will have to evaluate ‘a(t)’ in a loop, because it produces a matrix (obviously) for every value of ‘t’. I leave that to you, because I do not know what you want to do with your function.

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by