Need help finding intersection of two curves using fzero function

4 ビュー (過去 30 日間)
Syam Angalakuditi
Syam Angalakuditi 2019 年 9 月 6 日
コメント済み: Star Strider 2019 年 9 月 7 日
I'm new to MatLab (just started using it 2 days ago), and currently my goal is for the program to spit out the values of the points of intersections of two curves using the fzero command. This is my code:
syms x
y1 = x^8;
y2 = power(4,x);
f(x) = y1-y2;
fzero (f,-0.86)
The x value of the point of intersection is supposed to be x=-0.861345, however when I enter this code in, it outputs
ans =
-0.8357
, which isn't the correct value. When I change the value of the number inside the fzero command, it outputs a different number each time. How do I fix this? Thank you.

採用された回答

Star Strider
Star Strider 2019 年 9 月 6 日
With symbolic variables, use the vpasolve function:
syms x
y1 = x^8;
y2 = power(4,x);
f(x) = y1-y2;
intersection = vpasolve(f)
producing:
intersection =
-0.8613453323096513195240262391528
To use fzero, first use the matlabFunction function to create ‘f’ as an anonymous function (here):
ffcn = matlabFunction(f)
intersection = fzero(ffcn, -1)
producing:
intersection =
-0.861345332309651
Experiment to get the result you want.
  2 件のコメント
Syam Angalakuditi
Syam Angalakuditi 2019 年 9 月 6 日
Thank you very much for the detailed answer! The assignment requires that i use the fzero command to do the problem so I will be using that one.
Star Strider
Star Strider 2019 年 9 月 7 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by