plotting anonymous functions with multiple variables
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!