Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
MATLAB help with functions
조회 수: 1 (최근 30일)
이전 댓글 표시
>> x=[0:1:10]
x =
0 1 2 3 4 5 6 7 8 9 10
>> y=(exp(1).^(0.2*x/0.2))*cos((100-1).^(1/x))
Error using /
Matrix dimensions must agree.
>> y=(exp(1).^(0.2*x/0.2))*(cos((100-1).^(1/x))
y=(exp(1).^(0.2*x/0.2))*(cos((100-1).^(1/x))
↑
Error: Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.
Did you mean:
>> y=[exp(1).^(0.2*x/0.2)]*[cos((100-1).^(1/x))]
Error using /
Matrix dimensions must agree.
>>
Im trying to insert this function to plot a graph
i already have the values of k,m and c
댓글 수: 0
답변 (2개)
John D'Errico
2019년 10월 23일
편집: John D'Errico
2019년 10월 23일
Ok, you know that you have to use .^ to raise to a power. Then look carefully at the error message. What does it tell you?
"Error using /
Matrix dimensions must agree."
MATLAB did not like the / operator there? Why not? Because you did not use ./ instead.
You use the dotted operators to tell MATLAB to operate element-wise on a vector or array.
Where do we see a / in there?
y=(exp(1).^(0.2*x/0.2))*(cos((100-1).^(1/x))
I see two spots.
x/0.2
and
1/x
The fitrst case is not a problem, because MATLAB is able to divide a matrix or vector by a constant scalar with no problem. It is the second case where you have an issue. You need to use 1./x instead.
Oh, by the way, this is a silly thing to do here:
exp(1).^(0.2*x/0.2)
You clearly know what exp does!!!! So you might write
exp(0.2*x/0.2)
But even there, then why not make things even simpler? The last time I checked, we learned that:
0.2*x/0.2 == x
So you could just write your expression as:
y = exp(x)*(cos((100-1).^(1./x));
댓글 수: 1
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!