Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

help with creating a function

조회 수: 1 (최근 30일)
Ozan Mirzanli
Ozan Mirzanli 2020년 4월 9일
마감: MATLAB Answer Bot 2021년 8월 20일
how can i create this function which is named "myfun"
f(x,y) = sin(x+y) if x<y
cos(x + y/x) if x=y
e^y/x if x>y
  댓글 수: 1
Muhammad Adeel Ahsan Awan
Muhammad Adeel Ahsan Awan 2020년 4월 9일
What exactly do you want ?
Would x and y be given in input or you just want to print the implicit equations ?

답변 (1개)

BN
BN 2020년 4월 9일
Try this
function F = myfun(x,y)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if x<y
F = sin(x+y);
end
if x == y
F = cos(x + (y/x));
end
if x>y
F = exp(y/x);
end
end
  댓글 수: 2
Ozan Mirzanli
Ozan Mirzanli 2020년 4월 9일
what should i write on fprintf to function to work?
BN
BN 2020년 4월 9일
Nothing, Just open new script page from Matlab then save the code into it and then save it on desktop for example. then choose desktop as a current folder. now you can call function like this:
T = myfun(1,3)
% or
something = myfun(6,6)
you can use any x or y

태그

Community Treasure Hunt

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

Start Hunting!

Translated by