How ı can write this function on Matlab
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
채택된 답변
Sulaymon Eshkabilov
2020년 6월 4일
Hi,
Here is one of the possible solutions for x having a single value:
function Y = MY_fun(x)
if x>=1 && x<10
Y = exp(-x-1)/(log10(x)+log(x));
elseif x>=10
Y=sin(3*x)/sqrt(3*pi);
else
Y = x^(-exp(1)+x)+sqrt(x)*abs(x);
end
end
댓글 수: 13
Homework well done!
thanks for your answer but its doesnt work
Error like that.....
Cannot find an exact (case-sensitive) match for 'soru3'
The closest match is: Soru3 in C:\Users\HP OMEN\Desktop\MATLAB\Soru3.m
Did you mean:
>> Soru3
where did you get: Soru3 or soru3
In the above code, there is no such function or command.
The posted code doesn't match the equations.
@Sulaymon: we discourage people from posting fully working solutions to homework problems, as that invites cheating.
If you want to allow array inputs: make sure the formulae themselves allow array operations (so .* etc). Pre-allocate an output vector. Then for every piece of the function create a logical mask. You can fill your output with y(L)=f(x(L));.
my file's name is Soru3
@Rik please can u show me how i can do this. because its dont work still :(
Rik
2020년 6월 5일
It is your homework, not mine. Show that you have put in some effort. You already have a good idea about how to solve it, because you have a nearly correct answer. What did you try?
thats right but im working about that. i didnt understand whats wrong ...
clc;
clear all;
function y(L)=f(x(L))
if x>=1 || x<10
Y = exp(-x-1)/(log10(x)+log(x));
elseif x>=10
Y=sin(3*x)/sqrt(3*pi);
else
Y = x^(-exp(1)+x)+sqrt(x)*abs(x);
end
end
You should only ever have exactly one script that contains "clear all" in your code base, as part of a script that is designed to reset MATLAB including closing all graphics and files and triggering garbage collection.
Having "clear all" in code is rather like Wile E. Coyote exploding the bridge underneath himself and expecting to stay safe in mid-air as long as he does not look down.
Your code does not ever call your function f.
function y(L)=f(x(L))
That syntax is not valid. The left side of the "=" in a function statement must be one of:
- A single named plain variable with no indexing at all (including no structure references)
- [] around a list of named plain variables variables with no indexing at all (including no structure references). Commas are recommended between the variable names, but spaces are also accepted. Semi-colons are not accepted
- The special name varargout may be used as the left side by itself, or as the last entry in a list
The right side of the "=" in a function statement must be one of:
- a single named plain variable with no indexing at all (including no structure references) that acts as the function name
- function name as above followed by () with nothing in the ()
- function name as above followed by () and inside the () a comma-separated list of named plain variables with no indexing at all (including no structure references).
- Inside the () the special name varargin may be used as the only entry, or as the last entry in a list
- Inside the () the special token ~ may be used in place of any entry, such as function f(~,x)
Your code is not valid syntax because it tries to index the output variable, and because inside the () list on the right, it uses something that is not a plain variable or ~
Sulaymon comments:
%clc; % no need
%clear all; % no need
function Y=f(x) % Must be
% The rest comes here
end
thanks for your comment but i got it. wrong was not in code, in my matlab version. İts okay now.
Thanks again :)
Your code had a few potential errs which are not MATLAB version problem.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

