work(x, xvector, fdata) Unrecognized function or variable 'x'.

6 ビュー (過去 30 日間)
Ali Aliev
Ali Aliev 2022 年 1 月 22 日
コメント済み: Image Analyst 2022 年 1 月 22 日
function [a0,a1]=work(x,xvector,fvector)
fun=@(X,xdata) X(1)*exp(X(2)*xdata);
X0=rand(1,2);
A=lsqcurvefit(fun,X0,xvector,fvector);
fprintf('\n The answer for part a\n');
fprintf('\n V=%fe^(%f*P) \n',A(1),A(2));
fprintf('\n The answer for part b\n');
fprintf('The value of Volume at 1.05 bar by model is %f m^3\n',A(1)*exp(A(2)*x));
%Lagrange Method
xvalue = linspace(startingx, endingx, numberOfElements);
for i=1:length(xvector)
p=1;
for j=1:length(xvector)
if i~=j
p=p*((xvalue-xvector(j))/(xvector(i)-xvector(j)));
end
end
yvalue=yvalue+(p*fvector(i));
end
fprintf('\n The equation by Lagrange is:\n');
yvalue
fprintf('\n The answer for part c\n');
fprintf('The value of Volume at 1.5 bar by Lagrange is %f m^3\n',vpa(subs(yvalue,xvalue,x)));
fprintf('\n The answer for part d\n');
fprintf('\n The absolute difference between volume by predicted model and Lagrange interpolation is %f m^3\n',abs((A(1)*exp(A(2)*x))-(vpa(subs(yvalue,xvalue,x)))));
end
PLEASE CAN YOU HELP ME FIX THE ERROR (LINE 4)

回答 (1 件)

Image Analyst
Image Analyst 2022 年 1 月 22 日
  2 件のコメント
Ali Aliev
Ali Aliev 2022 年 1 月 22 日
i saw your answer but it did not fixed the problem
Image Analyst
Image Analyst 2022 年 1 月 22 日
Well, what is x? You say that MATLAB says it's undefined. What did you assign to x when you called work()? So in your code:
x = ????????????
xVector = ??????????????
fvector = ???????????????
% Now call the function:
[a0,a1]=work(x,xvector,fvector)
What are the ??????? in your code? You had to assign something to them. MATLAB won't just make up something for them out of thin air -- what if it makes up something you didn't want? You have to tell it.
You didn't just push the green run triangle without assigning something for x, xvector, and fvector, did you? Doing that also won't tell MATLAB what to use - they'll be undefined.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by