채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 6월 4일

0 개 추천

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
madhan ravi 2020년 6월 4일
Homework well done!
Emre Tutucu
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
where did you get: Soru3 or soru3
In the above code, there is no such function or command.
Rik
Rik 2020년 6월 4일
편집: Rik 2020년 6월 4일
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
Emre Tutucu 2020년 6월 4일
my file's name is Soru3
Emre Tutucu
Emre Tutucu 2020년 6월 4일
@Rik please can u show me how i can do this. because its dont work still :(
Rik
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
Walter Roberson
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.
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
Emre Tutucu
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 :)
Your code had a few potential errs which are not MATLAB version problem.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by