MATLAB Answers

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

5 views (last 30 days)
i have written
z=100;
for x=1:1:20
y=x*x
if y==z
fprintf(x)
end
end

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 18 Sep 2020
Edited: Stephen Cobeldick on 18 Sep 2020
>> f = @(x) x.^2 - 100;
>> x = fzero(f,pi)
x = 10

  3 Comments

rakesh kumar
rakesh kumar on 18 Sep 2020
Dear Stephen,thanks for the solution. But if you don't mind can you explain what does @(X) means.or send me the link where I can know about it. Thanks again
Stephen Cobeldick
Stephen Cobeldick on 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).

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by