I can't really find why matlab won't plot this equation, I run into an error as soon as i try to run it

조회 수: 1 (최근 30일)
x = 0 : 0.01 : 10 ;
y= ((exp(-0.5.*x))*(4-x))-2;
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
% Now, plot the f(x) -> x:
plot(x, y)
% Set axes labels:
xlabel('x')
ylabel('y')

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 3월 1일
You need to use times, .* for multiplying arrays (of compatible sizes) element-wise -
As the error states, mtimes, * is reserved for matrix multiplication.
x = 0 : 0.01 : 10 ;
% vv
y= ((exp(-0.5.*x)).*(4-x))-2;
% Now, plot the f(x) -> x:
plot(x, y)
% Set axes labels:
xlabel('x')
ylabel('y')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by