简体   繁体   English

如何使用一个函数的输出变量作为另一个函数的输入

[英]How to use output variables of a function as input for another function

I would like to use the output of a function as input for a function that builds a polynom: 我想将函数的输出用作构建多项式的函数的输入:

here is my code: 这是我的代码:

function c = interpolation(x, y)
    n = length(x);
    V = ones(n);
    for j = 2:n
         V(:,j)  = x.*V(:,j-1);
    end
     c = V \ y;
     disp(V) 
    for i = 0:n-1
      fprintf('c%d= %.3f\n', i, c(i+1));
    end

     polynome(c);
     function p = polynome(x)
         n = length(x);
         for l= 0:n-1
             polynome = polynome * x^l;
         end
     end

The first function alone, works. 仅第一个功能有效。 That means my code works if I comment starting from line 13 to end, and I get the c values, whose number depends from the length of the entered x vector in the beginning. 这意味着如果我从第13行开始注释到我的代码,我的代码将起作用,并且得到c值,其值取决于开头输入的x向量的长度。

I want to use that c values, to build a polynom of this form: p(x) = c0 + c^1*x1 + c2^x2 + .... + c(n-1)^x(n-1) and plot that polynom, with the points aswell xi,yi given at the beginning through the 2 vectors as input of the function interpolation. 我想使用该c值来构建这种形式的多项式: p(x) = c0 + c^1*x1 + c2^x2 + .... + c(n-1)^x(n-1)并绘制该多项式,并在开始时通过2个向量给出xi,yi点作为函数插值的输入。

Can someone help me here? 有人可以帮我吗?

make a separate function polynome eg 制作一个单独的函数多项式,例如

function y=polynome(x,c)
  y=sum(c.*x.^(0:length(c)-1));

or just use 或只是使用

y=sum(c.*x.^(0:length(c)-1)); 

to compute the polynome for your coefficients c. 计算系数的多项式c。

If you have multiple values of x, eg 如果您有多个x值,例如

x=[0:.1:3]';

y=repmat(x,1,numel(c)).^repmat((0:numel(c)-1),numel(x),1)*c';

should give you the values of the polynome 应该给你polynome的价值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将一个函数的输出值用作另一个MATLAB的输入 - How to use output values of one function as input of another MATLAB 如何在另一个函数中使用matlab函数的输出? - How to use the output of matlab function in another function ? 使用一个函数作为另一个函数的输入 - Use a function as input for another function function 句柄到 function 与多个 output 和文件数据存储中的输入变量 - function handle to function with multiple output and input variables in filedatastore 如何从另一个函数中的一个函数获得输出? - How get an output from a function in another function? 如何对不同的输入变量使用SPMD并按顺序保存输出? - How to use SPMD for different input variables and save the output in order? 在同一个Simulink模型中,如何使用matlab函数的输出向量作为查找表的输入? - How to use the output vector of a matlab function as an input for a lookup table in the same Simulink model? 使用具有动态变量的函数 - Use a function with dynamic variables 将输出用作Simulink中Matlab功能块的新输入 - Use the Output as the New Input into Matlab Function block in Simulink 将输入提供给GUI并捕获输出以便在其他功能中使用 - Supply inputs to a GUI and catch the output in order to use it in another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM