简体   繁体   中英

MATLAB: how to plot a function with a matrix?

For an exercise at school, I'm trying to plot a function where the variable is a matrix.
The function is very simple: y=x^4
The matrix, x, is 0:0.01:20 so it has a range from 0 to 20, and there are 2000 between them.
My problem is, the scale of the x-axis is 0-2000, and not 0-20 as i'd suppose it to be.
According to the current graph: 1000^4=10000, while it should be: 10^4=10000.
What am I doing wrong?

If I understand your question correctly, this is how it should be done. To limit the range of the x-axis and y-axis: use these commands

ylim([minimumvalue maxvalue]);
xlim([minimumvalue maxvalue]);

Here is the answer to your question:

x =  0:0.01:20 ;
y =x.^4;

% plot function

plot(x,y);
title('My function')
xlabel('X-axis range')
xlim([0 20]) ![OUTPUT][1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM