Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help! im trying to plot the direction field for this equation in matlab and it i

ID: 3881755 • Letter: H

Question

Help! im trying to plot the direction field for this equation in matlab and it is not letting me plot. It keeps telling me (Error using *
Inner matrix dimensions must agree.) I do not know how to fix this! please help!

clc;
clear all;
[t,y]=meshgrid(-3:.3:3,-2:.3:2);
dy = 2*t*exp(-t.^2)-2*t*y;
dt = ones(size(dy));
dyu = dy./sqrt(dt.^2+dy.^2);
dtu = dt./sqrt(dt.^2+dy.^2);
quiver(t,y,dtu,dyu)
axis tight
xlabel('t')
ylabel('y')
title('dy/dt = 2*t*exp(-t.^2)-2*t*y')

also, I have having a problem with this equation, dy=(-2/ty)+sin(t)/(t^2)

Explanation / Answer

The little * between the 2 vectors is
matrix multiplication in Matlab.

To multiply 2 vectors or 2 matrices, the number of columns of
the left one must be same as number of rows of the right one.
These are called the inner dimensions of the 2 objects around
the "*" (inner since they both point towards the "*")

In your case, the number of columns of the left one vector
is not the same as the number of rows of the right one.

One way to fix this is to use ".*" instead of "*" only
for the middle "*".


Now instead of matrix multiplication, element by element multiplication
is done. This should fix the problem.

About the last equation ,I think this should work

dy = (-2./ty)+sint(t)./(t.^2)

assuming t to be a vector.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote