Can someone explain what's wrong with my formula?

조회 수: 5 (최근 30일)
Kevin
Kevin 2021년 9월 30일
댓글: Kevin 2021년 9월 30일
close all
clear
clc
syms t
omega = 2:2:6
omega = 1×3
2 4 6
I = 10
I = 10
C = 0.05
C = 0.0500
V = (-I./omega.*C)*cos(omega.*t)
Error using * (line 432)
Dimensions do not match.
fplot(V)
What is wrong with it? I get an error when I try to run it.

채택된 답변

Matt J
Matt J 2021년 9월 30일
편집: Matt J 2021년 9월 30일
Be careful of missing dots...
V = (-I./omega.*C).*cos(omega.*t)
  댓글 수: 1
Kevin
Kevin 2021년 9월 30일
Sorry I'm still relatively new to using matlab, but thank you so much for taking your time to answer :D

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 9월 30일
omega is a vector, so (-I./omega.*C) is a vector and cos(omega.*t) is a vector the same size.
So you have 1 x 3 row vector * 1 x 3 row vector. But the * operator is algebraic matrix multiplication, "inner product". In the expresson A*B then size(A,2) must equal size(B,1) -- the "inner" dimensions must match. The first 1 x 3 vector operand for the * operation has 3 columns. The second 1 x 3 vector operand for the * operation has 1 row. But 1 is not equal to 3, so the * operation fails.
The element-by-element multiplication operator is .* instead of *

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by