フィルターのクリア

solve function answer is a 2x1 matrix . how to assign it directly to 2 variables ?

2 ビュー (過去 30 日間)
Ruqaya
Ruqaya 2023 年 11 月 23 日
コメント済み: Ruqaya 2023 年 11 月 23 日
v=[2;0;2;1;0;9;3;9;6];
m=max(v);
n=mean(v);
syms x
f=@(x) 2*n-x;
g=@(x) (n/6)*x.^2-2*m;
ezplot(f,[-10,10]);
hold on
ezplot(g,[-10,10]);
grid on
title ('graphs of f(𝑥) and g(𝑥)')
legend ('f(x)','g(x)');
s=round(solve( 2*n-x == (n/6)*x.^2-2*m ,x),5);
'x1=manually input (1st ans given by solve function above)';
'x2=manually input (2nd ans given by solve function above)';
a=int(2*n-x-(n/6)*x.^2+2*m,x1,x2);
Unrecognized function or variable 'x1'.
  2 件のコメント
Ruqaya
Ruqaya 2023 年 11 月 23 日
i need s answer to show the following : x1= "first ans" & x2= ""2nd ans""
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 23 日
Note - The use of ezplot is not recommend. Use fplot instead.
Also, look into disp and fprintf / sprintf

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

回答 (1 件)

John D'Errico
John D'Errico 2023 年 11 月 23 日
編集済み: John D'Errico 2023 年 11 月 23 日
For example, I'll compute the mean of an array, which here will generate a vector of length 2.
A = rand(10,2);
mean(A,1)
ans = 1×2
0.4834 0.4685
Define this function handle:
splitvec = @(x) deal(x(1),x(2));
Now I can use that little toy I just built.
[xm1,xm2] = splitvec(mean(A,1))
xm1 = 0.4834
xm2 = 0.4685
It directly takes a vector of length 2, and returns 2 distinct variables. Personally, I will tell you that is a bad idea. That it is better to just return a vector, and index into it.
Of course, this works as well on symbolic results.
syms y
[y1,y2] = splitvec(solve(y^2 - 1 == 0,y))
y1 = 
y2 = 
1

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by