필터 지우기
필터 지우기

Info

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

how to create a function m-file in Matlab v.7.12?

조회 수: 1 (최근 30일)
MissA
MissA 2012년 12월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
How to create a function m-file to evaluate the function f(x)=((1+a)*sin(a*x)*exp(-a*x))/x
where a is given and a=0.3
??
Please Help
Thanks in advance
MissA

답변 (2개)

Walter Roberson
Walter Roberson 2012년 12월 12일
function f = my_func(x)
a = 0.3;
f = ((1+a) * sin(a*x) .* exp(-a*x)) ./ x;
end

Muruganandham Subramanian
Muruganandham Subramanian 2012년 12월 12일
[f]=my_func(x)
a=0.3;
f(x)=((1+a)*sin(a*x)*exp(-a*x))/x
return;
  댓글 수: 3
Muruganandham Subramanian
Muruganandham Subramanian 2012년 12월 13일
편집: Muruganandham Subramanian 2012년 12월 13일
If you want to write as a function file, this is the way, and 'x' is an i/p argument, that you can read it from workspace, beore running the function file, like >>x=3; % 'x' is variable
function f =my_func(x)
a=0.3;
f(x)=((1+a)*sin(a*x)*exp(-a*x))/x
return;
otherwise, you can do this using for looping operation.
Walter Roberson
Walter Roberson 2012년 12월 13일
If you try that and x contains any values that are not positive integers, then MATLAB will complain about you trying to index the array f. For example, if x was 1/2 then
f(x) = .....
would mean
f(1/2) = .....
and that is trying to assign a value to element # (1/2) in array f, which is not legal.
See my solution.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by