I am trying to to figure out how to have the following printed out in such manner:
x^2 - 4
derivative 1
function is 2x
evaluated at the root f( 2)
4
However i am having issues displaying/printing out the derivative of f which should be printiong out 2x, probably num2srt is not the right operator, can anone give me insight on which command/operator to use? seee code below;
format long
syms x
f= x^2 -4;
disp(f);
i =1;
r=2;
D1= ['derivative ', num2str(i)];
disp(D1);
der= diff(f,i);
D2=['funtion is', num2str(der)];
disp(D2);
x=r;
D3=['evaluated at the root f(',num2str(x),')'];
disp(D3);
fx=subs(der);
disp(fx);

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 8 月 7 日

0 投票

char(der) rather than num2str(der)
The result of diff() applied to a symbolic expression is a symbolic expression, not a number.

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 8 月 6 日

回答済み:

2022 年 8 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by