iterate values of x through the difference between 2 functions equal to 40. the final x must make the equations equal to 40

1 次查看(过去 30 天)
hi guys this is what i have so far. I am not sure how to make it test values of x until the function equals 40. Abs(F1-F2)=40
x=linspace(0,10,100);
F1=3*x+6;
F2=x.^2-log(x);
figure(2)
plot(x,F1,x,F2)
m=40;
w=abs(F1-F2);
if m=w

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-7-18
[~,idx]=min(abs(w-m))
out=w(idx)
  11 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2016-7-18
What If is doing in your code?
x=linspace(0,10,100);
F1=3*x+6;
F2=x.^2-log(x);
figure(2)
plot(x,F1,x,F2)
m=40;
w=abs(F1-F2);
[y,idx] = min(abs(w-m));
out = w(idx);
x(idx)

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2016-7-18
There are two roots for that, one roughly 1E-20 and the other roughly 8.6. Both of them are irrational and so will never be found by using linspace() on any finite number of points and testing for equality with 40. You will need to use a different approach such as fzero or solving symbolically.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by