フィルターのクリア

Solve an equation, for a variable, with prompts?

2 ビュー (過去 30 日間)
Kyle Langford
Kyle Langford 2021 年 4 月 4 日
回答済み: darova 2021 年 4 月 6 日
I am new to matlab. I am just trying to have some fun building my own equations with prompts. I was trying to write a code for a simple kinematic equation, like x=x_0+v_0*t
I tried this, and it works:
syms x x_0 v_0 t
equation = x==x_0+v_0*t
x_0=0;
v_0=5;
t=10;
equation = x==x_0+v_0*t
S=solve(equation,x,"IgnoreProperties",true)
I did some searching on here for prompting, and found a funny version. So I tried this which was fun:
while true
x = input('How about sending an x value over this way?');
if isscalar(x) && isnumeric(x); break; end
end
while true
y = input('Groovy. Got a spare y value too?');
if isscalar(y) && isnumeric(y); break; end
end
disp(x*y)
My question is, how could I set up this kinematic equation, and prompt for the variable I want to solve for?

採用された回答

darova
darova 2021 年 4 月 6 日
What about this?
function main
a = myprompt('Please enter a:');
b = myprompt('the same way b:');
function y = myprompt(s)
while true
y = input(s);
if isscalar(y) && isnumeric(y); break; end
end
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by