How do I write matlab code for solving the following equation ?

As we have been provided the y in terms of vector. How can we solve the vector x for corresponding values of y? Please help.
y=0:1:10;
y=x-sin(x)/sqrt(1+sin(x));

回答 (2 件)

Mischa Kim
Mischa Kim 2014 年 4 月 22 日
編集済み: Mischa Kim 2014 年 4 月 22 日

0 投票

Pawan, you could do
syms x
y = 0:1:10;
for n = 1:numel(y)
yn(n) = vpasolve(y(n)-x+sin(x)./sqrt(1+sin(x))==0);
end
Note, that there are numerous solutions for a particular y-value.

2 件のコメント

pawan
pawan 2014 年 4 月 22 日
編集済み: pawan 2014 年 4 月 22 日
Thanks Mischa. But could you do without having symbolic function by assuming any initial value of x say ,0.0001
Mischa Kim
Mischa Kim 2014 年 4 月 22 日
Sure, again, there are multiple solutions, which you will find depending on the starting value.
y = 0:1:10;
for n = 1:numel(y)
yn(n) = fsolve(@(x) y(n)-x+sin(x)/sqrt(1+sin(x)), 10);
end

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

Image Analyst
Image Analyst 2014 年 4 月 22 日

0 投票

If you want to do it numerically, how about
x=0:1:10;
y=x-sin(x)/sqrt(1+sin(x))
plot(x, y, 'bs-', 'LineWidth', 2);
% Try to find x for which y = 5.
desiredY = 5;
[minDiff, desiredXIndex] = min(abs(y - desiredY))
hold on;
plot(x(desiredXIndex), y(desiredXIndex), ...
'r*', 'MarkerSize', 15, 'LineWidth', 2);
grid on;

タグ

タグが未入力です。

質問済み:

2014 年 4 月 22 日

回答済み:

2014 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by