Function data into columns?
显示 更早的评论
Hello. I have created a function that inputs a vector of x-values, and outputs the value of the Taylor Polynomial of e^x for said x-values. My objective is to take this data, and output it into a single column using a single fprintf statement, but I have no clue how to do this due to my unfamiliarity with functions. Everytime I tried to output "TaylorExp(x)", I kept getting the output in rows. Note, there is a "Texp" output variable that I had to use within my assignment, but I also did not know where to incorporate it. Here is my code and any assistance would be appreciated.
function [Texp ] = TaylorExp(x) % function definition line
% H1: Computes e^x using a Taylor Series for x>=0
% Help Text:
% x = a vector of exponents, all values x >= 0
% Output Argument:
% Texp = a vector of e^x values computed using a Taylor Series
n=0; % sets iterations
x=[0:0.5:20];
while n<1
n=n+1;
if isinteger(x)
((x)^(n)/factorial(n))
else
exp(x)
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!