plotting anonymous functions with multiple variables

5 ビュー (過去 30 日間)
eternal
eternal 2011 年 4 月 24 日
I was given a polynomial similar to deltaP=F(q,v)=(u1+u2*v)*(n1+n2*q+n3*q.^2+n4*q.^3) where a linear and cubic polynomial are multiplied together. also I was given 2 arrays of data in order to solve for the n's and q's using polyfit or some other method. My question is how do I plot the deltaP? My current code solves for all the variables, then I define the function, but when I go to plot it I get an undefined q error message, does fplot work for this type of function, as it is still a 2d graph? or perhaps I am doing something wrong.
MATLAB code
cfm = [0 17.8 25.2 30.9 35.7 39.9 43.7 47.2 48.5]';
h20 = [.095 .06 .045 .043 .035 .03 .02 .008 0]';
u=polyfit(cfm,h20,3)
n=polyfit(cfm,h20,1)
f=@(v, q)(u(1)+u(2)*v)*(n(1)+n(2)*q+n(3)*q.^2+n(4)*q.^3);
fplot(f,[0 48.5]);
MATLAB code
thanks for any help

回答 (1 件)

Matt Fig
Matt Fig 2011 年 4 月 24 日
This is confusing to me. If I plot your vectors:
plot(cfm,h20)
It doesn't look cubic, though you could fit a cubic polynomial to this data. Part looks linear and part looks maybe quadratic, perhaps you meant that you need a piecewise fit? In your solution, u and n are switched, i.e., u should have two values and n should have 4 if we believe your function definition. Also, you have mixed up the order of the coefficients returned from POLYFIT.
I don't see how the function f can be related to your data. Is this homework?
Use EZPLOT to plot implicitly defined functions.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by