Need help plotting simple graph in matlab

Click For Summary
SUMMARY

The forum discussion addresses a common error encountered while plotting graphs in MATLAB. The user initially attempted to calculate the current I using the expression I=(V^3)-(1.4*V)+0.9, which resulted in the error "matrix must be square." The solution provided involves using element-wise operations by replacing the matrix power operator with the element-wise operator, resulting in the corrected code: I=(V.^3)-(1.4*V)+0.9. This adjustment allows for successful plotting of the graph.

PREREQUISITES
  • Familiarity with MATLAB syntax and operations
  • Understanding of element-wise versus matrix operations in MATLAB
  • Basic knowledge of plotting functions in MATLAB
  • Experience with vector and matrix manipulation in MATLAB
NEXT STEPS
  • Explore MATLAB's element-wise operations in detail
  • Learn about MATLAB plotting functions and customization options
  • Investigate common MATLAB errors and their solutions
  • Practice vector and matrix operations in MATLAB to enhance proficiency
USEFUL FOR

This discussion is beneficial for students, educators, and professionals who are learning MATLAB, particularly those encountering issues with graph plotting and matrix operations.

Fairy111
Messages
72
Reaction score
0

Homework Statement


I need to plot a graph in matlab,
i typed in the following,
V=[0:.2:20];
I=(V^3)-(1.4*V)+0.9;
plot(V,I)

It comes up with the error,
error using mpower, matrix must be square.

Any help into how to fix this problem would be great.

Thankyou



Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
A^2 = A*A, i.e. a matrix multiplication. Use A.^2 for element-wise operations:

V=[0:.2:20];
I=(V.^3)-(1.4*V)+0.9;
plot(V,I)

Ought to work.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K