Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

MATLAB help with functions

1 Ansicht (letzte 30 Tage)
rayan sharqawi
rayan sharqawi am 23 Okt. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
>> 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

Antworten (2)

John D'Errico
John D'Errico am 23 Okt. 2019
Bearbeitet: John D'Errico am 23 Okt. 2019
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));

rayan sharqawi
rayan sharqawi am 23 Okt. 2019
I still got this errorCapture.PNG

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by