保存符号方程式以备后用吗? [英] Saving a symbolic equation for later use?

查看:71
本文介绍了保存符号方程式以备后用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处 ,我正在尝试求解这样的符号方程组

From here, I'm trying to solve a symbolic system of equations like this

syms x y z;
[x, y, z] = solve('z = 4*x', 'x = y', 'z = x^2 + y^2')
x =
0
2

y =
0
2

z =
0
8

除了我的方程是在m文件中的不同点处生成的,并且具有随机系数.我的问题是我该如何完成以下任务...

except that my equations are generated at different points in the m-file and with random coefficients. My question is how can I accomplish the following...

// Generate the first equation.
n = *random number generated here*;
E1 = (z == n*x + 2*n);   // <--- How to save this symbolic equation to use in "solve(...)" later?

// Other work, generate other eqs.
...

// Solve system of eqs.
[x, y, z] = solve( E1 , E2, E3)   // What/How to call/use the previously saved symbolic equations.

感谢您的帮助!

编辑

已更新以更好地说明目标.

Updated to better explain objective.

推荐答案

使用 sprintf 如果要保留随机生成的n值以供以后与solve一起使用:

Use sprintf if you want to keep the randomly generated value of n for later use with solve:

n = *random number generated here*;
E1 = (z == n*x + 2*n);
Eq1 = sprintf('z == %f*x + 2*%f',n,n);

您可以使用%f上的参数来查看要包含的精度.

You can play with the parameters on %f to see how much precision you want to include.

这篇关于保存符号方程式以备后用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆