**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# Solve an equation not getting a result

3 views (last 30 days)

Show older comments

Hey here is my code, I don't know why I am not getting an answer,

E=9*10^3; nu=0.3; k=0.01; G=2*10^3; evide0=0.8;increment1=0.0001;

e1=[0:increment1:1];

s01=0;

s1=[s01];s1(1)=s01;

for i=2:length(e1)

syms x

a=double(solve(increment1==((1/3)*(k/(1+evide0))*((x-s1(i-1))/x))+((1/3*G)*(x-s1(i-1)))),x);

s1(i)=a

if s1(i)>500

s1=s1(1:(i-1));

break

end

end

I am not getting a value in a

##### 0 Comments

### Answers (2)

Star Strider
on 12 Feb 2022

The solve call was causing problems because the conversion and testing in the if block would then not work correctly because the logical test does not work for symbolic variables. Also, the ‘a’ result was frequently empty, and that effectively stopped the iteration. So I changed the call to fsolve (and made approprite changes to the code for the expression it was to solve) that elimnated those problems, and temporarily changed the value of ‘increment1’ to something reasonable that I could execute in the online Run feature here.

% syms x

E=9*10^3;

nu=0.3;

k=0.01;

G=2*10^3;

evide0=0.8;

increment1=0.0001;

increment1 = 0.01;

e1=[0:increment1:1];

s01=0;

% s1=[s01];

s1{1}=s01;

for i=2:length(e1)

% syms x

a = fsolve(@(x)increment1 - ((1/3)*k/(1+evide0)) * (x-s1{i-1})/x + ((1/3*G)*(x-s1{i-1})) ,(1+1i)*1000)

if isempty(a)

s1{i} = {0};

else

s1{i}=a;

end

if real(s1{i})>500

s1{i} = s1{1:(i-1)};

break

end

end

Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.

a = -1.2222e-05 - 1.8158e-19i

Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.

a = -2.5762e-05 + 1.2116e-14i

Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.

a = -3.9783e-05 + 3.8858e-14i

a = -5.4050e-05 + 2.9737e-14i

a = -6.8465e-05 + 2.2520e-14i

a = -8.2979e-05 + 2.6854e-14i

a = -9.7564e-05 + 2.3754e-14i

a = -1.1220e-04 + 2.5388e-14i

a = -1.2688e-04 + 2.6473e-14i

a = -1.4159e-04 + 2.7222e-14i

a = -1.5633e-04 + 2.7756e-14i

a = -1.7109e-04 + 2.7273e-14i

a = -1.8587e-04 + 2.7566e-14i

a = -2.0066e-04 + 2.7299e-14i

a = -2.1547e-04 + 2.7475e-14i

a = -2.3029e-04 + 2.7318e-14i

a = -2.4513e-04 + 2.7194e-14i

a = -2.5997e-04 + 2.7286e-14i

a = -2.7482e-04 + 2.7209e-14i

a = -2.8968e-04 + 2.7272e-14i

a = -3.0454e-04 + 2.7222e-14i

a = -3.1941e-04 + 2.7180e-14i

a = -3.3429e-04 + 2.7220e-14i

a = -3.4917e-04 + 2.7192e-14i

a = -3.6406e-04 + 2.7168e-14i

a = -3.7895e-04 + 2.7194e-14i

a = -3.9384e-04 + 2.7178e-14i

a = -4.0874e-04 + 2.7164e-14i

a = -4.2364e-04 + 2.7182e-14i

a = -4.3855e-04 + 2.7198e-14i

a = -4.5346e-04 + 2.7213e-14i

a = -4.6837e-04 + 2.7226e-14i

a = -4.8328e-04 + 2.7238e-14i

a = -4.9820e-04 + 2.7233e-14i

a = -5.1312e-04 + 2.7229e-14i

a = -5.2804e-04 + 2.7238e-14i

a = -5.4296e-04 + 2.7246e-14i

a = -5.5789e-04 + 2.7244e-14i

a = -5.7282e-04 + 2.7251e-14i

a = -5.8775e-04 + 2.7249e-14i

a = -6.0268e-04 + 2.7255e-14i

a = -6.1761e-04 + 2.7261e-14i

a = -6.3254e-04 + 2.7266e-14i

a = -6.4748e-04 + 2.7271e-14i

a = -6.6242e-04 + 2.7276e-14i

a = -6.7736e-04 + 2.7275e-14i

a = -6.9230e-04 + 2.7280e-14i

a = -7.0724e-04 + 2.7283e-14i

a = -7.2218e-04 + 2.7287e-14i

a = -7.3712e-04 + 2.7290e-14i

a = -7.5207e-04 + 2.7291e-14i

a = -7.6701e-04 + 2.7291e-14i

a = -7.8196e-04 + 2.7291e-14i

a = -7.9691e-04 + 2.7294e-14i

a = -8.1186e-04 + 2.7294e-14i

a = -8.2681e-04 + 2.7294e-14i

a = -8.4176e-04 + 2.7295e-14i

a = -8.5671e-04 + 2.7297e-14i

a = -8.7166e-04 + 2.7298e-14i

a = -8.8662e-04 + 2.7300e-14i

a = -9.0157e-04 + 2.7300e-14i

a = -9.1652e-04 + 2.7302e-14i

a = -9.3148e-04 + 2.7304e-14i

a = -9.4644e-04 + 2.7306e-14i

a = -9.6139e-04 + 2.7307e-14i

a = -9.7635e-04 + 2.7309e-14i

a = -9.9131e-04 + 2.7310e-14i

a = -0.0010 + 0.0000i

a = -0.0010 + 0.0000i

a = -0.0010 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0011 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0012 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0013 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0014 + 0.0000i

a = -0.0015 + 0.0000i

a = -0.0015 + 0.0000i

a = -0.0015 + 0.0000i

figure

plot(e1, real([s1{:}]))

grid

xlabel('e_1')

ylabel('s_1')

This runs without error. Make appropriate changes if it does not produce the desired result.

.

##### 2 Comments

rita richa
on 12 Feb 2022

thank you, I actually were searching for a positive real answer not an immaginary one but I found the problem, I had a mistake in the equation.

Thanks a lot for your time.

Star Strider
on 12 Feb 2022

My pleasure!

If my Answer helped you solve your problem, please Accept it!

.

### See Also

### Tags

### Community Treasure Hunt

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

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)