如何使用fsolve​函数求解含手动输入变​量的非线性方程?。

18 Ansichten (letzte 30 Tage)
先写一个m文件,存放方程:
function F = mytry(a,x)
a = input('请输入a值'); % a是变量值,需要输入
F(1) = x(1) - x(2) -a;
F(2) = 2*x(1) - 8*x(2) -4;
再写一个main函数,如下:
clear
fun1 = @mytry(a,x);
x0 = [0,0];
x = fsolve(fun1,x0)
在MATLAB工作区调用main函数时,
结果显示Unbalanced or misused parentheses or brackets.
求解为什么?

Akzeptierte Antwort

百家乐登录平台网址【www.xbs3512.com】
把a定义成全局变量就好了
clear all
clc
global a
a = input('请输入a值'); % a是变量值,需要输入
fun1 = @mytry ;
x0 = [0,0];
x = fsolve(fun1,x0)
function F = mytry(x)
global a
F(1) = x(1) - x(2) -a;
F(2) = 2*x(1) - 8*x(2) -4;
end

Weitere Antworten (0)

Kategorien

Mehr zu 编程 finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!