How to solve equation with "Error using symengine A square matrix is expected",

Hello
My code below written to solve an equation works well with a single input parameter d (line 8). However, when I have a vector for the input "d" as shown in line 9, Matlab complain that I have "symengine". here is my code.Any help is appreciated.
clear all
clc
close all
% definition of constants
Y=9*10^(-13);
% d=20*10^-3;
d= linspace(1*10^-3,20*10^-3,10);
q=1.6*10^(-19);
kB=4.0434e-21;
er=2.8320e-11;
mp=1*10^-9;
mn=1*10^-9;
c=3.2520e+23;
kr=q*(mp+mn)/(er);
no=Y/(q*(mp+mn));
kdo=kr*no*no/c;
Lb= (q^2)/(8*pi*er*kB);
syms Vs
b=(Lb*q*(Vs./d))./(kB );
num=besselj(1,sqrt(-8*b));
den=sqrt(-2*b);
Fb=num./den;
kd=kdo*Fb;
eqn = (((kd*kr*c)^0.5).*d.^2)./(mp+mn)==Vs;
solVs = solve(eqn,Vs);
vpa(solVs)

 채택된 답변

eqn = (((kd*kr*c).^0.5).*d.^2)./(mp+mn)==Vs;
Notice the .^ instead of ^

댓글 수: 5

Thanks However, how do I get my final answer as a function of the vector? When I enter d as a single number I get the final answer(Vs). However when i enter d as a vector like d= linspace(10*10^-3,20*10^-3,10); it gives me Empty sym: 0-by-1.
That answer is correct.
You have 10 equations in 1 variable (Vs).
When you ask to solve() multiple equations, you are asking what combination of variable values can satisfy all of the equations at the same time.
There is no single value Vs that can satisfy all 10 of your equations at the same time.
You could arrayfun() your solve() -- though I recommend vpasolve() instead of solve() . Also, if you do use arrayfun() you will need to use 'uniform', 0, as arrayfun() cannot handle symbolic results directly.
friet
friet 2017년 4월 8일
편집: friet 2017년 4월 8일
Thanks for your comment. May be my previous comment was a little bit unclear and I would like to make it clear here. When I entre d=10*10^-3; I have Vs=1634.9 and for d=2*10^-3; I have Vs=6736.5. When I put just single d it works fine. however when I enter d=[10*10^-3; 2*10^-3] i was expecting to see vs=[1634.9;6736.5]. But it is giving me empty matrix. I have no idea how to create matrix. is it like to make a for loop for each variable d?
temp = arrayfun( @vpasolve, eqn, 'Uniform', 0);
solVs = horzcat( temp{:} );

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2017년 4월 8일

댓글:

2017년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by