i want to write a code where equation is y=x*x. if y=100 what is the value of x?

1 Ansicht (letzte 30 Tage)
i have written
z=100;
for x=1:1:20
y=x*x
if y==z
fprintf(x)
end
end

Akzeptierte Antwort

Stephen23
Stephen23 am 18 Sep. 2020
Bearbeitet: Stephen23 am 18 Sep. 2020
>> f = @(x) x.^2 - 100;
>> x = fzero(f,pi)
x = 10
  3 Kommentare
Stephen23
Stephen23 am 18 Sep. 2020
Bearbeitet: Stephen23 am 18 Sep. 2020
This
@(x) x.^2 - 100
defines an anonymous function:
fzero uses that function to find the zero crossing (i.e. the input value for which the function output is zero).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 18 Sep. 2020
z = 100 ;
x = 1:20 ;
y = x.^2 ;
y(x==z)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by