필터 지우기
필터 지우기

Unknown Error at MATRIX 1

조회 수: 1 (최근 30일)
Jomarck
Jomarck 2022년 10월 20일
댓글: Walter Roberson 2022년 10월 20일
I am trying to find the amplitude "A" and the two phase shifts phi1 and phi2. I keep getting an error on the same line as MATRIX_1, but I keep getting this error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
I have been trying to look for a solution to this error, but I have been doing this for an hour. Help?
function [A, phil1, phil2] = compute_exp_wave_params(omega, f);
w1 = omega(1);
w2 = omega(2);
t = 1:100;
MATRIX_1 = [1cos (w1 * 1), sin(w1 * 1), cos(w2 * 1), -sin(w2 * 1);
1cos (w1 * 2), sin(w1 * 2), cos(w2 * 2), -sin(w2 * 2);
1cos (w1 * 3), sin(w1 * 3), cos(w2 * 3), -sin(w2 * 3);
1cos (w1 * 4), sin(w1 * 4), cos(w2 * 4), -sin(w2 * 4);
1cos (w1 * 5), sin(w1 * 5), cos(w2 * 5), -sin(w2 * 5)];
MATRIX_2 = inv(MATRIX_1);
MATRIX_3 = [f(1), f(2), f(3), f(4), f(5)];
MATRIX_4 = (MATRIX_2) * (MATRIX_3);
phi1 = asin(MATRIX_4(2));
phi2 = acos(MATRIX_4(4));
A = exp(MATRIX_4(1))
omega = [2, 1]; %Code to call my function
f = [
3.6065
0.3667
1.4256
5.8902
2.4701
5.7549
6.7604
0.5410
0.7121
5.4867
3.0614
3.7443
9.4376
1.0680
0.4235
3.8090
4.2015
2.6949
9.4275
2.3896
0.3477
2.0766
5.4891
2.3897
7.1422
4.9902
0.4210
1.0192
5.9064
2.6747
4.6899
8.2396
0.7240
0.5404
4.7919
3.5370
3.1433
9.8207
1.5520
0.3686
2.9341
4.8379
2.4729
8.5089
3.4427
0.3623
1.4912
5.8619
2.4523
5.9108
6.5501
0.5228
0.7412
5.5589
3.0073
3.8406
9.3348
1.0178
0.4339
3.9286
4.1183
2.7361
9.5149
2.2723
0.3481
2.1673
5.4218
2.3908
7.3098
4.7918
0.4114
1.0652
5.9252
2.6401
4.8201
8.0581
0.6942
0.5590
4.8976
3.4668
3.2116
9.8104
1.4752
0.3738
3.0463
4.7536
2.4940
8.6533
3.2843
0.3585
1.5596
5.8280
2.4368
6.0694
6.3391
0.5058
0.7721
5.6254
2.9555
3.9408];
[A, phi1, phi2] = compute_exp_wave_params(omega, f)
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 10월 20일
1cos
what is 1cos? Function and variable names cannot start with a number in MATLAB
Jomarck
Jomarck 2022년 10월 20일
My bad, a typo that followed through because I copied and pasted cos.
Now tha I ran the code, it's telling me that there are not enough input arguments for cos.
Also the error for the same line in MATRIX_1 is now: Error in compute_exp_wave_params (line 7)
Not really sure where to go from here.

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

답변 (1개)

Walter Roberson
Walter Roberson 2022년 10월 20일
편집: Walter Roberson 2022년 10월 20일
The parsing rules are different inside [] or {} than outside those.
Inside those the parser is always looking to see if the spacing could reasonably support the interpretation that adjacent elements are distinct elements of a list. Consider for example
[1 2]
[1 -1]
[x y]
[1 (x+y)/2]
in each of those cases it is obvious that you are defining separate list elements.
But now consider
[x (x+y)/2]
is that a two element list? Is that x indexed at (x+y)/2? Is that a function x that accepts 0 or one argument being invoked first with no arguments, the result added to y, divide by 2, and pass the result to x? Yes there really are functions that accept such a thing, such as true((true+3)/2) would invoke true with no parameters, get scalar true, convert to double 1, add 3 to get 4, divide by 2 to get 2, and then invoke true(2) to return a 2x2 logical array.
So in MATLAB the rules inside [] and {} are
p+q or p+ q or p + q is addition, a single element
p +q is p and unary plus operator on q, a pair of elements
p-q or p- q or p - q is subtraction
p -q is p and unary minus operator on q, a pair of elements
pOPq or pOP q or p OP q or p OPq for all other operators is OP(p, q), a single element
p(q) and p( q) is p invoked on or indexed at q, not multiplication
p (q) is two separate elements, not function invocation or indexing or multiplication
So...
[cos (w1 * 2)]
is a two element vector, the first invoking cos with no parameters.
This is different than if you are outside of [] {}.
  댓글 수: 3
Jomarck
Jomarck 2022년 10월 20일
Thank you. I've been able to pass the unknown error, but now it wont allow me to inverse the matrix since it isn't a perfect square. This is more on my end, there is a missing variable somewhere. Either way, thank you for your help.
Walter Roberson
Walter Roberson 2022년 10월 20일
What is your current code for Matrix 1?

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by