# How do you perform generic value in MATLAB?

5 views (last 30 days)
Please, I would like guidance regarding how to run a generic simulation with values I don't know__ eg __ez .
theta = fi([0,pi/4,pi/3,pi/2,(2*pi)/3,(3*pi)/4,pi])
er=sin(theta)*ex+cos(theta)*ez
eo=cos(theta)*ex-sin(theta)*ez

John D'Errico on 19 Dec 2021
Edited: John D'Errico on 19 Dec 2021
If you do not know those parameters, then you don't know them. What "simulation" would you run? What meaning does it have?
At best, you can use symbolic tools to leave them undefined, but still you have essentially nothing but an equation. You can evaluate things as a function of theta, but your result will have those parameters in there as unknowns.
theta = fi([0,pi/4,pi/3,pi/2,(2*pi)/3,(3*pi)/4,pi])
theta =
0 0.7854 1.0472 1.5708 2.0944 2.3562 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
Your next problem is that sin and cos are not defined for that class.
whos theta
Name Size Bytes Class Attributes theta 1x7 336 embedded.fi
So while we can define ex and ez as symbolic parameters, at best you can convert them to doubles to use trig functions. But even then, you still are not running a simulation of any sort, because those parameters are undefined.
syms ex ez
dtheta = double(theta);
er=sin(dtheta)*ex+cos(dtheta)*ez
er =
eo=cos(dtheta)*ex-sin(dtheta)*ez
eo =
But if you try to compute the sin and cos of theta itself, it fails:
er=sin(theta)*ex+cos(theta)*ez
Error using * (line 55)
Set Best Precision only valid for numeric data.
Could you convert to double, then back fo an fi objects for the numerical values? I suppose, but that seems to miss the point of using fi in the first place, and I have a funny feeling that syms won't mix well with the fi objects.

William Rose on 19 Dec 2021
What is "fi()" in the first line of your code?
I am not sure I understand your question.
You can try different values for ex and ez. For each combination, you can plot er versus theta and eo versus theta.
If I remove the function "fi()" in line 1 of your code, and make guesses for the values of ex and for ez, and plot, then I get the following:
theta = [0,pi/4,pi/3,pi/2,(2*pi)/3,(3*pi)/4,pi];
ex=1; ez=0.5;
er=sin(theta)*ex+cos(theta)*ez;
eo=cos(theta)*ex-sin(theta)*ez;
plot(theta,er,'-r.',theta,eo,'-b.');
title('ex=1, ez=0.5');
legend('er','eo'); xlabel('theta');
Does that help?
##### 2 CommentsShowHide 1 older comment
William Rose on 20 Dec 2021
@John D'Errico, thank you.

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by