# how can I create a function with multiple variables?

21 ビュー (過去 30 日間)
Vipin Kumar Yadav 2019 年 12 月 6 日
Answered: Image Analyst 2019 年 12 月 7 日
hello,
I am really novice with MATLAB and I am having a hardtime writing this code.
So I have to make a function in this format
y= a(1) + (a(2)/z) + (a(3)*x) + (a(4)*x^2) + ((a(5)*x)/z) + ((a(6)*x^2)/z)
where
y=function(x,z) ###### x,y,z can be taken from database and some values are mentioned below.)
and a(1), a(2), a(3), a(4), a(5), a(6) are constant that needed to be defined
x=[0.1 0.2 0.3 0.4 0.5 0.6 0.65 0.7];
y=[1 3 5 7 15 50 1 85];
z=[313 313 313 313 313 313 313 313]
any suggestion will be of great help.
Thanks

#### 0 件のコメント

サインイン to comment.

### 件の回答 (2)

JESUS DAVID ARIZA ROYETH 2019 年 12 月 6 日
y=@(a,x,z) a(1) + (a(2)./z) + (a(3).*x) + (a(4).*x.^2) + ((a(5).*x)./z) + ((a(6).*x.^2)./z);
x=[0.1 0.2 0.3 0.4 0.5 0.6 0.65 0.7];
a=[1 2 3 6 4 1];%put your values here
z=[313 313 313 313 313 313 313 313]
returnfunction=y(a,x,z)

#### 0 件のコメント

サインイン to comment.

Image Analyst 2019 年 12 月 7 日
Try this:
function y = yourFunctionName(x, z)
% x,y,z can be taken from database and some values are mentioned below.)
a = .... % Whatever you have to do do get a.
% a(1), a(2), a(3), a(4), a(5), a(6) are constant that needed to be defined
y= a(1) + (a(2)/z) + (a(3)*x) + (a(4)*x^2) + ((a(5)*x)/z) + ((a(6)*x^2)/z)
You'll need to figure out how to get the "a" values, and need to figure out how to call the function (by which I mean somehow you need to assign the x and x inputs. Save this in yourFunctionName.m or use whatever name you want for the function just make sure it's the same on the function line as the name of the m file is.

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

Translated by