Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Chris
Chris le 20 Fév 2011
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

Réponses (2)

Matt Fig
Matt Fig le 20 Fév 2011
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 le 20 Fév 2011
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 *.

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by