How to write code for solving system of nonlinear inequality

9 ビュー (過去 30 日間)
Greg
Greg 2022 年 6 月 29 日
コメント済み: Greg 2022 年 6 月 30 日
I am very new to matlab and programming in general. I believe I am not using syntax properly to get it to do what I want, or I just don't understand the logic. In any case this is the problem I need help solving in matlab:
y(x)={ 6x^2-5x+14} x>=0
y(x)={9x-3} x>0
range is -10 to 10 in increments of 1.
This is the code I tried. It only shows the x array when I run it and nothing else (no error message). I know it's probably way off but I'm only going off of a few help videos and a programming structure lecture.
x=-10:1:10
for i=1:21
if x>=0
y(x)=6*x^2-5*x+14
elseif x>10
disp('x out of range')
end
if x<0
y(x)=9*x-3
elseif x<-10
disp('x out of range')
end
end

採用された回答

Walter Roberson
Walter Roberson 2022 年 6 月 29 日
x=-10:1:10;
for i=1:length(x)
if x(i)>=0
y(i)=6*x(i)^2-5*x(i)+14;
elseif x(i)>10
disp('x out of range')
end
if x(i)<0
y(i)=9*x(i)-3;
elseif x(i)<-10
disp('x out of range')
end
end
y
y = 1×21
-93 -84 -75 -66 -57 -48 -39 -30 -21 -12 14 15 28 53 90 139 200 273 358 455 564

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by