converting a program to function
Show older comments
Hi guys,
I have written a probrem depend on x values and also ı want to convert to a function it can usefull in commond windows like:
>>G(1.15)
G{1.15}=1.200
ı want do that with function command
my program
x= input('pleasei');
x1=x;
count=1;
sums=1;
lastterm=1;
inc2=0;
fact=2;
newterm=1;
n=2;
rcx=1;
while rcx/1000<newterm
count=count+1;
if rcx/1000<newterm && count~=1
x1=x1*x;
end
while sums/1000<abs(lastterm)
%count=count+2;
ust= x^2;
inc2=inc2+2;
%inc3=inc3+1;
alt=(inc2)^2;
farkterm1=-(ust/alt);
lastterm=lastterm*farkterm1;
sums = sums+lastterm;
%ax1=abs(lastterm)/1000;
end
if count~=1
n=n+1;
fact=fact*n;
newterm=sums/fact;
rcx=rcx+newterm;
else
rcx=sums;
end
end
thank you
Answers (1)
Determine which variables are inputs and outputs. Then assign them in this manner:
function [out1, out2, out3] = yourFunctionName(in1, in2, in3)
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!