フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Help in creating function , built in equation

1 回表示 (過去 30 日間)
Ali Tawfik
Ali Tawfik 2019 年 8 月 23 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi All,
I am trying to build in function, including equation which is a result of another code,
I understand function is a separate script but I just need to do something smart, no to add the equation in every time ,
below is the code:
clear all;
clc;
syms x y;
an=solve(-15== 10*x+2*y,y);
ap=solve(10*x+2*y ==20,y);
yin=[an,ap]
damontwo % Name of the function
%% function
function damontwo(x)
x=input('please enter number ')
yin(:,1)=input('Enter equation to solve ')
end
When I type an: I got an error ?, however, when I type equation, it works, so could anyone please help me, how could I introduce that to the function ?
Thanks,

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 8 月 23 日
syms x y;
eqns = damontwo(x,y);
solve(eqns)
%% function
function yin = damontwo(x,y)
yin(1) = input('Enter first equation to solve ');
yin(2) = input('Enter second equation to solve ');
end
  5 件のコメント
Ali Tawfik
Ali Tawfik 2019 年 8 月 24 日
Thanks Walter, I mean yin(:,1)=an
(an) is a result of a previous equation
clear all;
clc;
syms x y;
an=solve(-15== 10*x+2*y,y);
ap=solve(10*x+2*y ==20,y);
yin=[an,ap]
damontwo % Name of the function
%% function
function damontwo(x)
x=input('please enter number ')
yin(:,1)=input('Enter equation to solve ')
end
Walter Roberson
Walter Roberson 2019 年 8 月 24 日
Why are you bothering to prompt at all? Why not use an if you have it already?

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by