Create a vector 't' and vector 'f' where 'f' is a mathematical function to plot.

Create a vector 't' which consists of 100 numbers uniformly spread between 0.01 and 1. Also create a vector 'f' which includes the corresponding 100 values of the mathematical function t^(2) + 3t – 15. Plot 'f' versus 't'. This is what I have so far:
% Creating a vector 't' which consists of 100 numbers uniformly spread between 0.01 and 1
t=0.01+(1-0.01).*rand(1,100);
% Creating a vector 'f' which includes the corresponding 100 values of the mathematical function t^(2)+3t-15
f=t.^2+3*t-15
%add code
% Plotting 'f' versus 't'
figure(1),plot(f,t)

댓글 수: 1

You have made the same mistake again. You need to plot(t,f) instead of plot(f,t).

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

 채택된 답변

Jim Riggs
Jim Riggs 2018년 3월 5일
편집: Jim Riggs 2018년 3월 5일
How about this:
t = 0:.01:1;
f = t.^2+3.*t-15;
figure;
plot(t,f,'b');
grid;

댓글 수: 7

can u put in comments please?
do you have a specific question?
I'm really confused on this part of the question: "Also create a vector 'f' which includes the corresponding 100 values of the mathematical function t^(2) + 3t – 15."
First of all, the question calls for a series of values that are "uniformly spaced". This means that they have the same spacing from one to the next. It has nothing to do with randomness. so the line:
t=0: 0.01 : 1
creates a vector t starting at 0, with increments of 0.01 and ending at 1, so you have a vector from 0 to 1 in 100 equal increments.
the statement "create a vector 'f' which includes the corresponding 100 values of the mathematical function t^(2) + 3t – 15" means to create a vector f, using the 100 values of t, according to the function t^(2) + 3t - 15. This is accomplished in the line of code:
f=t.^2+3.*t-15
note that the syntax ".^" and ".*" (using the dot) means to perform this operation on each element of the vector.
Also, why isn't it t=1:0.01:100?
The instruction says you want a uniform spread from .01 to 1, so 1 is the highest value. The expression 1: .01 : 100 says start at one and go to 100 in steps of .01. This is not what you want. You want to start at 0 and go to 1 in steps of 0.01, this is expressed as:
0: 0.01 : 1

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2018년 3월 5일

편집:

2018년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by