How ı can write this function on Matlab
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
採用された回答
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 件のコメント
madhan ravi
2020 年 6 月 4 日
Homework well done!
Emre Tutucu
2020 年 6 月 4 日
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
Sulaymon Eshkabilov
2020 年 6 月 4 日
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));.
Emre Tutucu
2020 年 6 月 4 日
my file's name is Soru3
Emre Tutucu
2020 年 6 月 4 日
@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?
Emre Tutucu
2020 年 6 月 5 日
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
Walter Roberson
2020 年 6 月 5 日
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.
Walter Roberson
2020 年 6 月 5 日
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 ~
madhan ravi
2020 年 6 月 5 日
Sulaymon comments:
%clc; % no need
%clear all; % no need
function Y=f(x) % Must be
% The rest comes here
end
Emre Tutucu
2020 年 6 月 5 日
thanks for your comment but i got it. wrong was not in code, in my matlab version. İts okay now.
Thanks again :)
Sulaymon Eshkabilov
2020 年 6 月 5 日
Your code had a few potential errs which are not MATLAB version problem.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
タグ
参考
2020 年 6 月 4 日
2020 年 6 月 5 日
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)

