필터 지우기
필터 지우기

How do I plot this non-linear function...

조회 수: 4 (최근 30일)
Chris
Chris 2011년 2월 20일
This question is pretty elementary, but I'm new to MATLAB and am having trouble with this. I want two curves, one of r vs. T (which is easy, it's just a fourth power function) and one of r2 vs. T (on the same graph). That's fine, except r2 is r multiplied by some function of T (which will be on the x-axis) that I called k.
T=180:1:360
k=.8823-((T-179)*(.0039))
s=1.1e-2
r=s*(T.^4)
r2=k*s*(T.^4)
plot(T,r,'-k',T,r2)
This doesn't work...This is just an example, but my head still isn't around the matrix interpretation of plotting, so any tips for plotting stuff like this or non-linear functions in general would be appreciated

답변 (2개)

Matt Fig
Matt Fig 2011년 2월 20일
One minor change will make it work.
T = 180:1:360;
k = .8823-((T-179)*(.0039));
s = 1.1e-2;
r = s*(T.^4);
r2 = k.*s.*(T.^4); % Or r2 = k.*(s*(T.^4)); Or r2=(k*s).*(T.^4);
plot(T,r,'-k',T,r2)
In general, whenever you have two or more vectors and you want their product to be a vector, use element-by-element multiplication (include the dot). Look at a small example:
a = 1:3
b = 5:7
a.*b
The same goes for division and exponentiation.

Matt Tearle
Matt Tearle 2011년 2월 20일
You should be getting an error on the line that defines r2 (before you even get to the plot). As Matt Fig points out, the multiplication there should be .* (element-wise), not *.

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by