Problem adding two symbolic functions

4 ビュー (過去 30 日間)
Hossein
Hossein 2017 年 2 月 28 日
コメント済み: Kuifeng Zhao 2021 年 5 月 18 日
Hi, I have a problem adding two fuctions with deriatives of symbolic variables. The main purpose ist to solve a differential equation for an amount of x and y to achieve Ux Uz. Can any body help me?
syms x y Ux Uz
U_x(x,y,Ux)=Ux*cos(x)*cos(y);
U_z(x,y,Uz)=Uz*cos(x)*cos(y);
A1=diff(U_x,x)+0.5*(diff(U_z,x))^2;
Error:
Error using symfun/privResolveArgs (line 181) Symbolic function inputs must match.
Error in sym/privBinaryOp (line 819) args = privResolveArgs(A, B);
Error in + (line 7) X = privBinaryOp(A, B, 'symobj::zip', '_plus');

採用された回答

Sid Jhaveri
Sid Jhaveri 2017 年 3 月 2 日
Hi Hossein,
As the error suggests, both the inputs need to match. Try defining your U_x and U_z as follows:
U_x(x,y,Ux,Uz)=Ux*cos(x)*cos(y);
U_z(x,y,Ux,Uz)=Uz*cos(x)*cos(y);
After changing U_x and U_z as above, your code should work properly.
  1 件のコメント
Kuifeng Zhao
Kuifeng Zhao 2021 年 5 月 18 日
Thanks. I came across a similar problem with error "Error in *X = privBinaryOp(A, B, 'symobj::mtimes');" and your answer helped solved my problem.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 2 日
A1 = diff(U_x(x,y,Ux),x)+0.5*(diff(U_z(x,y,Uz),x))^2;
That is, diff(U_x,x) gives a function result, as does diff(U_z,x), and then you were trying to add two functions with different arguments. But if you invoke U_x(x,y,Ux) then that becomes an expression result, and you diff() the two expressions and then you can add the expressions.

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by