I want a program in which the user enters the function and the program display or plot that function

val=input("Enter Function",'s');
func= str2func( ['@(x) ' val ] );
x=(1:5);
y=func(x);
disp(y)
this is an example code that i wrote but code does not support x^2 and other amount of x^"any number"

 採用された回答

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023 年 5 月 10 日
編集済み: Antoni Garcia-Herreros 2023 年 5 月 10 日
Hello Amir,
When you input your function you need to add the dot , just like this: x.^n

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeThermal Analysis についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 5 月 10 日

コメント済み:

2023 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by